Skip to content

Commit ff91b65

Browse files
authored
feat: support custom config for preset-env (#169)
* feat: support custom config for preset-env * docs: fix typo
1 parent 809bdf6 commit ff91b65

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

packages/babel-preset-beidou-client/README.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
This preset includes the following plugins:
44

5-
- babel-preset-env
6-
- babel-preset-react
7-
- babel-preset-stage-2
8-
- babel-plugin-typecheck
9-
- react-hot-loader
5+
- @babel/preset-env
6+
- @babel/preset-react
7+
- @babel/preset-typescript [optional]
8+
- @babel/plugin-proposal-function-sent
9+
- @babel/plugin-proposal-decorators
10+
- @babel/plugin-proposal-class-properties
11+
- @babel/plugin-proposal-export-namespace-from
12+
- @babel/plugin-proposal-numeric-separator
13+
- @babel/plugin-proposal-throw-expressions
14+
- babel-plugin-add-module-exports
15+
- react-hot-loader/babel [only for dev]
1016

1117
## Install
1218

@@ -27,3 +33,16 @@ This preset support dynamic compile browser targets, set [browserslist](https://
2733
```
2834

2935
Or using default browserslist `['>1%', 'last 4 versions', 'not ie < 9']`.
36+
37+
### Config in `.babelrc`
38+
39+
```json
40+
{
41+
"presets": [["babel-preset-beidou-client", { "typescript": true }]]
42+
}
43+
```
44+
45+
**Options**
46+
47+
- typescript: enable typescript
48+
- env: config passed to preset-env

packages/babel-preset-beidou-client/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ try {
2020

2121
module.exports = function (api, opt) {
2222
api.assertVersion(7);
23-
23+
opt = opt || {};
24+
const envOption = opt.env || {};
2425
const presets = [
2526
[
2627
env,
27-
{
28-
useBuiltIns: 'entry',
29-
targets: {
30-
browsers,
28+
Object.assign(
29+
{
30+
useBuiltIns: 'entry',
31+
corejs: '3.0.0',
32+
targets: {
33+
browsers,
34+
},
3135
},
32-
},
36+
envOption
37+
),
3338
],
3439
];
3540

packages/babel-preset-beidou-client/test/babel-client.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ describe('babel-preset-client', () => {
3232
assert.equal(typeof result.presets[1][1], 'object');
3333
});
3434

35+
it('should overrite defalt env config', () => {
36+
assert(typeof preset === 'function');
37+
const result = preset(mockApi, { env: {
38+
corejs: '2.0.0',
39+
} });
40+
assert(Array.isArray(result.presets));
41+
assert.equal(typeof result.presets[0][1], 'object');
42+
assert.equal(result.presets[0][1].corejs, '2.0.0');
43+
});
44+
3545
});

0 commit comments

Comments
 (0)