forked from zaihui/hui-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
76 lines (75 loc) · 1.85 KB
/
babel.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* jest搭配ts使用需要对babel进行配置
* 参考:
* - https://jestjs.io/docs/en/getting-started.html#using-typescript
*
* 更多关于测试的说明可参考文档[UnitTest.md]
*/
const isTest = process.env.NODE_ENV === 'test'
const testConfig = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
],
plugins: [
[
'@babel/plugin-transform-react-jsx',
{
pragma: 'Nerv.createElement',
},
],
[
'babel-plugin-auto-import',
{
declarations: [
{
default: 'Nerv',
path: 'nervjs',
},
],
},
],
[
'@babel/plugin-proposal-decorators',
{
legacy: true,
},
],
/**
* typescript可以直接在class中声明属性,而js目前只能在constructor中创建属性
* 相关的提案已经进入stage-3:https://github.com/tc39/proposal-class-fields
* node从v12开始支持这一特性
* 由于babel-preset-env默认不包含stage-x中的插件
* 所以对于v12之前的node,需要手动启用class-properties
* 参考:
* https://www.babeljs.cn/docs/babel-preset-env#how-does-it-work
* https://babeljs.io/docs/en/babel-plugin-proposal-class-properties
* https://babeljs.io/docs/en/next/babel-plugin-transform-typescript.html
* https://devblogs.microsoft.com/typescript/typescript-and-babel-7/
* https://github.com/babel/babel/issues/6604
* https://github.com/tc39/proposals
*/
'@babel/plugin-proposal-class-properties',
],
}
const devConfig = {
sourceMap: true,
presets: [
[
'taro',
{
framework: 'react',
ts: true,
},
],
],
}
const config = isTest ? testConfig : devConfig
module.exports = config