Skip to content

Commit 921b300

Browse files
committed
feat(core): make babel-preset configurable
Also add babel-runtime plugin
1 parent 3263cc4 commit 921b300

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/smooth-core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
"dependencies": {
3636
"@babel/core": "^7.2.2",
3737
"@babel/plugin-proposal-class-properties": "^7.2.3",
38+
"@babel/plugin-transform-runtime": "^7.2.0",
3839
"@babel/polyfill": "^7.2.5",
3940
"@babel/preset-env": "^7.2.3",
4041
"@babel/preset-react": "^7.0.0",
4142
"@babel/register": "^7.0.0",
43+
"@babel/runtime": "^7.3.1",
4244
"@emotion/core": "^10.0.6",
4345
"@loadable/babel-plugin": "^5.2.2",
4446
"@loadable/component": "^5.2.2",

packages/smooth-core/src/babel/preset.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const common = {
66
],
77
}
88

9-
const nodeConfig = {
9+
const nodeConfig = opts => ({
1010
...common,
1111
presets: [
1212
...common.presets,
@@ -18,12 +18,13 @@ const nodeConfig = {
1818
targets: {
1919
node: 'current',
2020
},
21+
...opts['preset-env'],
2122
},
2223
],
2324
],
24-
}
25+
})
2526

26-
const webConfig = {
27+
const webConfig = opts => ({
2728
...common,
2829
presets: [
2930
...common.presets,
@@ -33,18 +34,23 @@ const webConfig = {
3334
modules: false,
3435
loose: true,
3536
useBuiltIns: 'entry',
37+
...opts['preset-env'],
3638
},
3739
],
3840
],
39-
}
41+
plugins: [
42+
...common.plugins,
43+
['@babel/plugin-transform-runtime', opts['transform-runtime']],
44+
],
45+
})
4046

4147
function isWebTarget(caller) {
4248
return Boolean(caller && caller.name === 'babel-loader')
4349
}
4450

45-
module.exports = api => {
51+
module.exports = (api, opts = {}) => {
4652
if (api.caller(isWebTarget)) {
47-
return webConfig
53+
return webConfig(opts)
4854
}
49-
return nodeConfig
55+
return nodeConfig(opts)
5056
}

0 commit comments

Comments
 (0)