-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
109 lines (100 loc) · 2.21 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const { NODE_ENV } = process.env;
const paths = {
output: path.join(__dirname, '/build'),
src: './client/js'
};
let htmlConfig = {
template: path.resolve(__dirname, './client/index.html')
};
if(NODE_ENV === 'production'){
htmlConfig = {
...htmlConfig,
minify: {
collapseWhitespace: true
}
}
}
let plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'common-[chunkhash].[id].js',
minChunks: ({ resource }) => /node_modules/.test(resource)
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
filename: 'manifest-[hash].[id].js'
}),
new HtmlWebpackPlugin(htmlConfig),
new webpack.DefinePlugin({
'__DEV__': NODE_ENV === 'development',
'process.env': {
'NODE_ENV': JSON.stringify(NODE_ENV || 'development')
}
})
];
if (NODE_ENV !== 'production'){
plugins = [
...plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
]
}
const entry = ['./client/js/index.js'];
if(NODE_ENV !== 'production'){
entry.unshift('webpack-hot-middleware/client');
}
module.exports = {
devtool: NODE_ENV === 'production' ? 'eval' : 'eval-source-map',
entry,
output: {
path: paths.output,
filename: '[name]-[hash].[id].bundle.js',
publicPath: '/'
},
plugins,
module: {
rules: [
{
enforce: 'pre',
test: /.vue$/,
loader: 'eslint-loader',
exclude: /node_modules/
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
extensions: ['.js', '.vue', '.scss'],
alias: {
'scss': path.resolve(__dirname, 'client/scss')
}
},
devServer: {
publicPath: '/',
historyApiFallback: true,
noInfo: true,
log: false,
reload: true,
stats: {
colors: true
}
}
};