forked from chesterhow/js-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.config.js
82 lines (69 loc) · 2.05 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const pathsToClean = ['dist'];
const config = {
entry: {
main: './src/index.js',
// entry point of the app
vendor: [
'react',
'react-dom',
'react-router-dom',
'prop-types'
]
// global dependencies
},
output: {
filename: '[name].[chunkhash:8].js',
path: path.resolve(__dirname, 'dist'),
publicPath: ''
// necessary for HMR to know where to load the hot update chunks
},
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
}, {
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader', 'postcss-loader']
})
}, {
test: /\.(jpg|png|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 25000,
name: '[name].[ext]'
}
}
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
// split global dependencies into a separate 'vendor' file.
// 'manifest' file extracts webpack's runtime code from the 'vendor'
// file. this prevents the 'vendor' file's chunkhash from changing
// every build.
new webpack.HashedModuleIdsPlugin(),
// ensures the 'vendor' file's chunkhash stays the same when code
// is modified
new ExtractTextPlugin('styles.[contentHash:8].css'),
// split css into separate file
// note: do not use this for dev as it does not work with HMR
new HtmlWebpackPlugin({ template: 'index.html' }),
// generates 'index.html' and handles 'script' and 'link' tags
new CleanWebpackPlugin(pathsToClean, { verbose: true })
// removes 'dist' folder before building
]
};
module.exports = config;