Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add babel config and ts config #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) }]
Expand Down
3 changes: 2 additions & 1 deletion packages/bisheng/src/config/getTSCommonConfig.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default function ts() {
export default function ts(tsConfig) {
return {
target: 'es6',
jsx: 'preserve',
moduleResolution: 'node',
declaration: false,
...tsConfig,
};
}
7 changes: 4 additions & 3 deletions packages/bisheng/src/config/getWebpackCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'),
Expand Down
5 changes: 4 additions & 1 deletion packages/bisheng/src/utils/get-bisheng-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const defaultConfig = {
webpackConfig(config) {
return config;
},

tsConfig: {},
babelConfig(config) {
return config;
},
entryName: 'index',
root: '/',
filePathMapper(filePath) {
Expand Down
2 changes: 2 additions & 0 deletions packages/bisheng/test/utils/get-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'),
Expand Down