-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.js
95 lines (92 loc) · 2.25 KB
/
webpack.prod.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var autoprefixer = require('autoprefixer');
var postPxToEm = require('postcss-px-to-em');
var StyleLintPlugin = require('stylelint-webpack-plugin');
var flag = false;
process.argv.forEach(function (item) {
if (item === '--precache') {
flag = true;
}
});
module.exports = {
entry: {
app: ['./src/index.js'],
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: 'js/[name].[chunkhash:6].js',
chunkFilename: "js/chunk/[name].[chunkhash:6].js"
},
resolveLoader: {
root: path.join(__dirname, 'node_modules')
},
resolve: {
extensions: ['', '.js'],
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: "eslint-loader",
exclude: /node_modules/
}
],
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader']
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url?limit=10000&name=images/[name].[hash:6].[ext]'
},
{
test: /\.(woff|eot|ttf).*?$/i,
loader: 'url?limit=10000&name=fonts/[name].[hash:6].[ext]'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css!postcss')
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css!postcss!sass')
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
}),
new ExtractTextPlugin('css/[name].[chunkhash:6].css'),
new webpack.DefinePlugin({
__DEV__: false
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {warnings: false}
}),
new StyleLintPlugin({
configFile: '.stylelintrc',
failOnError: true,
}),
],
postcss: function () {
return [autoprefixer, postPxToEm({base: 16})];
},
eslint: {
failOnError: true
},
devtool: 'cheap-module-source-map'
};
if (flag) {
module.exports.entry = Object.assign(module.exports.entry, {
'service-worker-registration': ['./src/service-worker-registration.js']
})
}