forked from dantaeyoung/es6-webpack2-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
120 lines (101 loc) · 3.14 KB
/
webpack.prod.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
110
111
112
113
114
115
116
117
118
119
120
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const srcDir = path.resolve(__dirname, '..', 'src');
const distDir = path.resolve(__dirname, '..', 'dist');
module.exports = {
// Where to fine the source code
context: srcDir,
// No source map for production build
devtool: 'hidden-source-map',
entry: [
'./index.js',
],
output: {
// The destination file name concatenated with hash (generated whenever you change your code).
// The hash is really useful to let the browser knows when it should get a new bundle or use the one in cache
filename: 'main-[hash].js',
// The destination folder where to put the output bundle
path: distDir,
// Wherever resource (css, js, img) you call <script src="..."></script>,
// or css, or img use this path as the root
publicPath: '/',
// At some point you'll have to debug your code, that's why I'm giving you
// for free a source map file to make your life easier
// sourceMapFilename: 'main-[hash].map',
},
// The devServer config is here to enable you to run the production build. I know you wanna see
// the output of this awesome config with me (Webpack 2).
devServer: {
contentBase: distDir,
historyApiFallback: true,
port: 3000,
compress: true,
inline: false
},
module: {
rules: [
{
// Webpack, when walking down the tree, whenever you see `.js` file use babel to transpile
// the code to ES5. I don't want you to look into the node_modules folder.
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader',
],
},
{
test: /\.css$/,
exclude: /node_modules/,
// It's production mode and I don't want inline CSS so put all my CSS into a file
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader',
}),
},
{
test: /\.(jpg|jpeg|png|gif|ico|svg)$/,
loader: 'url-loader',
query: {
// if less, bundle the asset inline, if greater, copy it to the dist/assets folder using file-loader
limit: 10000,
name: 'assets/[name].[hash].[ext]'
},
},
]
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new HtmlWebpackPlugin({
// where to find the html template
template: path.join(srcDir, 'index.html'),
// where to put the generated file
path: distDir,
// the output file name
filename: 'index.html'
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true
},
comments: false
}),
// Put all css code in this file
new ExtractTextPlugin('app-[hash].css'),
],
};