es6语法转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//规则
rules: [
{
test:/\.js$/,
use:[
{
loader: "babel-loader",
options: { //用babel-loader需要把es6=>es5
presets:[
'@babel/preset-env'
],
plugins:[//增加对es7语法识别 class A{} 以及对装饰器的识别@log https://babeljs.io/docs/en/babel-plugin-proposal-decorators
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose" : true }],
["@babel/plugin-transform-runtime"]
]
}
}
],
include: path.resolve(__dirname, 'src'), //指定在在哪个目录中找
exclude: /node_modules/ //排除node_modules目录,在使用@babel/plugin-transform-runtime会导致去node_modules中查找
}
]

语法校验

下载eslintrc.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//规则
rules: [//loader特点,希望单一,loader有顺序的,从右向左执行,从下到上执行
{//https://eslint.org/demo/
test:/\.js$/,
use:[
{
loader: "eslint-loader",
options: {
enforce: "pre" //previous post https://www.npmjs.com/package/eslint-loader
}
}
]
}
]