diff --git a/README.md b/README.md index 17fdb25..e3fec62 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,18 @@ You can consult [webpack postcss-loader's documentation](https://webpack.js.org/ To modify the webpack config, you can extend the config like [this](https://github.com/ant-tool/atool-build#配置扩展). +#### babelConfig: (config) => config + +> default: (config) = config + +You can consult [webpack babel-loader's documentation](https://webpack.js.org/loaders/babel-loader/#options) + +#### tsConfig: Object + +> default: {} + +You can extend [typescript config](https://www.typescriptlang.org/tsconfig) + #### transformers: Object[] > [{ test: /\.md$/, use: [MarkdownTransformer](https://github.com/benjycui/bisheng/blob/master/packages/bisheng/src/transformers/markdown.js) }] diff --git a/packages/bisheng/src/config/getTSCommonConfig.js b/packages/bisheng/src/config/getTSCommonConfig.js index e4cac17..cb5e6e1 100644 --- a/packages/bisheng/src/config/getTSCommonConfig.js +++ b/packages/bisheng/src/config/getTSCommonConfig.js @@ -1,8 +1,9 @@ -export default function ts() { +export default function ts(tsConfig) { return { target: 'es6', jsx: 'preserve', moduleResolution: 'node', declaration: false, + ...tsConfig, }; } diff --git a/packages/bisheng/src/config/getWebpackCommonConfig.js b/packages/bisheng/src/config/getWebpackCommonConfig.js index f5ed921..948cc98 100644 --- a/packages/bisheng/src/config/getWebpackCommonConfig.js +++ b/packages/bisheng/src/config/getWebpackCommonConfig.js @@ -25,7 +25,8 @@ export default function getWebpackCommonConfig() { : '[name].css'; const babelOptions = getBabelCommonConfig(); - const tsOptions = getTSCommonConfig(); + const customBabelOptions = bishengConfig.babelConfig(babelOptions); + const tsOptions = getTSCommonConfig(bishengConfig.tsConfig); /** @type {import('webpack').Configuration} */ const config = { @@ -61,14 +62,14 @@ export default function getWebpackCommonConfig() { test: /\.jsx?$/, exclude: /node_modules/, loader: require.resolve('babel-loader'), - options: babelOptions, + options: customBabelOptions, }, { test: /\.tsx?$/, use: [ { loader: require.resolve('babel-loader'), - options: babelOptions, + options: customBabelOptions, }, { loader: require.resolve('ts-loader'), diff --git a/packages/bisheng/src/utils/get-bisheng-config.js b/packages/bisheng/src/utils/get-bisheng-config.js index 3c71848..847b56d 100644 --- a/packages/bisheng/src/utils/get-bisheng-config.js +++ b/packages/bisheng/src/utils/get-bisheng-config.js @@ -23,7 +23,10 @@ const defaultConfig = { webpackConfig(config) { return config; }, - + tsConfig: {}, + babelConfig(config) { + return config; + }, entryName: 'index', root: '/', filePathMapper(filePath) { diff --git a/packages/bisheng/test/utils/get-config.test.js b/packages/bisheng/test/utils/get-config.test.js index 2621469..d759eef 100644 --- a/packages/bisheng/test/utils/get-config.test.js +++ b/packages/bisheng/test/utils/get-config.test.js @@ -7,6 +7,7 @@ describe('bisheng/utils/get-bisheng-config', () => { it('should merge custom config to default config', () => { const bishengConfig = getBishengConfig(path.join(__dirname, '../fixtures/bisheng.config.js')); delete bishengConfig.webpackConfig; + delete bishengConfig.babelConfig; delete bishengConfig.filePathMapper; assert.equal(bishengConfig.postcssConfig.plugins.length, 3); @@ -21,6 +22,7 @@ describe('bisheng/utils/get-bisheng-config', () => { port: 8000, root: '/', devServerConfig: {}, + tsConfig: {}, transformers: [{ test: /\.md$/.toString(), use: path.join(__dirname, '..', '..', 'lib', 'transformers', 'markdown'),