-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.babel.js
80 lines (77 loc) · 1.96 KB
/
webpack.config.babel.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
77
78
79
80
import path from 'path';
import webpack from 'webpack';
import precss from 'precss';
import autoprefixer from 'autoprefixer';
const webpackConfig = {
devtool: 'source-map',
resolve: {
//自动扩展文件后缀名
extensions: ['.js', '.jsx', '.css']
},
entry: {
index: ['./js/index.js']
},
externals: {
react: 'react',
'react-dom': 'react-dom',
'prop-types': 'prop-types'
},
output: {
path: path.join(__dirname, 'publish/dist'), //打包输出目录
publicPath: './', //生成文件基于上下文路径
library: ['reactSwiper'],
libraryTarget: 'umd'
},
module: {
rules: [
// https://github.com/MoOx/eslint-loader
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
use: 'eslint-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader?pack=cleaner'],
}
],
},
plugins: [
// http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
//用来优化生成的代码 chunk,合并相同的代码
new webpack.optimize.AggressiveMergingPlugin(),
//用来保证编译过程不出错
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.LoaderOptionsPlugin({
options: {
// eslint 配置
eslint: {
emitError: true, // 验证失败,终止
configFile: '.eslintrc'
},
postcss () {
return {
defaults: [precss, autoprefixer],
cleaner: [autoprefixer({
flexbox: 'no-2009',
browsers: ['Chrome >= 35', 'Firefox >= 38',
'Android >= 4.3', 'iOS >=8', 'Safari >= 8']
})]
};
},
}
})
]
};
module.exports = webpackConfig;