forked from luoxue-victor/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabelLoader.js
44 lines (42 loc) · 910 Bytes
/
babelLoader.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
// [babel-loader 配置]
module.exports = ({ config, resolve, tsx }) => {
const babelConf = {
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
chrome: 59,
edge: 13,
firefox: 50,
safari: 8
}
}
],
[
'@babel/preset-typescript',
{
allExtensions: true
}
]
],
plugins: [
'@babel/plugin-transform-typescript',
'transform-class-properties',
'@babel/proposal-object-rest-spread'
]
}
if (tsx) {
babelConf.presets[1].pop()
babelConf.presets.push('@babel/preset-react')
babelConf.plugins.shift()
}
const baseRule = config.module.rule('babel').test(/.[jt]sx?$/)
return () => {
baseRule
.use('babel')
.loader(require.resolve('babel-loader'))
.options(babelConf)
}
}