-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.dist.config.js
159 lines (156 loc) · 4.63 KB
/
webpack.dist.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This is the "production" configuration for Webpack.
// Note that there is a lot of overlap with the "development" configuration, this could be avoided
// by using Webpack's "advanced configuration" (TO DO...)
//
// This configuration includes some extra goodies such as:
// -- Uglify to minify & compress JS more than Webpack will do own its own (I think?)
// -- If you use Moment.js it will ignore Moment's locales files which tend to be really large and
// most of the time aren't needed.
// -- It will also create compressed versions of bundled files. This can drastically speed up loadin
// time (especially on mobile!) when a server is configured to send them
// -- Any files you have specified in "assets" will be copied to the "dist/" directory, this
// technique could be used for other directories as well, such as "data/" for example
// -- Source maps for this configuration are smaller than what is produced by the dev config
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const extractSass = new ExtractTextPlugin({
filename: '[name].[chunkhash].css',
disable: process.env.NODE_ENV === 'development',
});
module.exports = {
entry: {
bundle: ['babel-polyfill', './src/index.js'],
},
cache: false,
devtool: 'cheap-module-source-map',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkhash].js',
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.geojson'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [
{
loader: 'css-loader',
},
{
loader: 'postcss-loader', // postcss loader so we can use autoprefixer
options: {
config: {
path: 'postcss.config.js',
},
},
},
{
loader: 'sass-loader',
},
{
loader: "@epegzz/sass-vars-loader",
options: {
files: [
path.resolve(__dirname, 'src/common/styleVars.js'),
],
},
},
],
fallback: [
{
loader: 'style-loader',
},
],
}),
},
{
test: /\.(json|geojson)$/,
use: 'json-loader',
},
{
test: /\.svg$/,
use: [
'babel-loader',
{
loader: 'svgr/lib/webpack',
options: {
svgo: false,
icon: true,
},
},
]
},
{
test: /\.(jpe?g|png|gif)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
{
test: /\.(eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
],
},
plugins: [
new UglifyJSPlugin({
test: /\.(js|jsx)$/,
mangle: false,
sourceMap: true,
compress: {
dead_code: true,
warnings: false, // Suppress uglification warnings
screw_ie8: true,
},
exclude: [/\.min\.js$/gi], // skip pre-minified libs && css
}),
extractSass,
new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]),
// codesplitting: vendor libraries
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
// eslint-disable-next-line
minChunks: function(module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1;
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity,
}),
new webpack.NoEmitOnErrorsPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
new HTMLWebpackPlugin({
template: 'src/index.html',
}),
// tell Webpack to copy static assets (images, icons, etc.) to dist/
new CopyWebpackPlugin([{ from: 'assets/', to: 'assets/' }]),
],
};