Skip to content

Commit

Permalink
feat(tsbb): add babel-option option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 2, 2021
1 parent 00263b7 commit 2994ca2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/tsbb/src/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function transformFile(fileStat: IFileDirStat, args: IBuildArgs, cjsPath?:
{
envName: args.currentEnvName,
outputPath,
babelOption: args.babelOption,
sourceMaps: args.sourceMaps,
comments: args.comments,
},
Expand Down
26 changes: 19 additions & 7 deletions packages/tsbb/src/babel/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ITransformOptions {
envName: string;
outputPath: string;
comments: boolean;
babelOption?: 'defalut' | 'none';
sourceMaps: boolean | 'inline' | 'both' | 'none';
}

Expand Down Expand Up @@ -72,16 +73,27 @@ export default (filePath: string, options: ITransformOptions, targets: ITargets)
loadOptions({ envName: options.envName || process.env.BABEL_ENV });
babelOptions.presets = [];
}
const transformOptions = options.babelOption === 'defalut' ? {
envName: options.envName || process.env.BABEL_ENV,
presets: [],
...babelOptions,
// comments: process.env.NODE_ENV === 'development' ? false : true,
// comments: false,
sourceMaps: options.sourceMaps === 'none' ? false : options.sourceMaps,
sourceFileName: path.relative(path.dirname(options.outputPath), filePath),
} : {}
console.log(transformOptions)
transformFile(
filePath,
{
envName: options.envName || process.env.BABEL_ENV,
presets: [],
...babelOptions,
// comments: process.env.NODE_ENV === 'development' ? false : true,
// comments: false,
sourceMaps: options.sourceMaps === 'none' ? false : options.sourceMaps,
sourceFileName: path.relative(path.dirname(options.outputPath), filePath),
...transformOptions,
// envName: options.envName || process.env.BABEL_ENV,
// presets: [],
// ...babelOptions,
// // comments: process.env.NODE_ENV === 'development' ? false : true,
// // comments: false,
// sourceMaps: options.sourceMaps === 'none' ? false : options.sourceMaps,
// sourceFileName: path.relative(path.dirname(options.outputPath), filePath),
},
(err, result: ITransformResult) => {
if (err) {
Expand Down
6 changes: 6 additions & 0 deletions packages/tsbb/src/command/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ export const publicOptions: IYargsOptions = {
type: 'boolean',
default: true,
},
'babel-option': {
describe: 'Whether to prohibit the default babel option.',
type: 'string',
choices: ['defalut', 'none'],
default: 'defalut',
},
};
2 changes: 2 additions & 0 deletions packages/tsbb/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface IMyYargsArgs extends Arguments {
copyFiles?: boolean;
'source-maps'?: boolean | 'inline' | 'both' | 'none';
sourceMaps?: boolean | 'inline' | 'both' | 'none';
'babel-option'?: 'defalut' | 'none';
babelOption?: 'defalut' | 'none';
output?: string;
o?: string;
timer?: number;
Expand Down

0 comments on commit 2994ca2

Please sign in to comment.