-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
63 lines (59 loc) · 1.94 KB
/
webpack.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
'use strict';
const isProd = process.env.NODE_ENV === 'production';
const { resolve } = require('path');
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const LiveReloadPlugin = require('webpack-livereload-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const SRC_DIR = resolve(__dirname, 'src');
const BUILD_DIR = resolve(__dirname, 'build');
module.exports = {
entry: resolve(SRC_DIR, 'js', 'main.js'),
output: {
path: BUILD_DIR,
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /.css$/,
loader: ExtractTextPlugin.extract(['css']),
},
{
test: /.(jpe?g|png|svg|ttf|eot|woff)(\?.+)?$/,
loader: 'file?context='+SRC_DIR+'/&name=[path][name].[ext]',
}
]
},
plugins: [
isProd ? null : new LiveReloadPlugin(),
new ExtractTextPlugin('styles.css'),
new CopyWebpackPlugin([
{
from: resolve(SRC_DIR, 'img'),
to: resolve(BUILD_DIR, 'img'),
}
]),
new ImageminPlugin({
optipng: {
optimizationLevel: 7,
},
jpegtran: {
progressive: true,
},
}),
new HtmlWebpackPlugin({
template: resolve(SRC_DIR, 'index.html'),
favicon: resolve(SRC_DIR, 'favicon.ico'),
hash: 'version', // awaiting PR merge: https://github.com/ampedandwired/html-webpack-plugin/pull/535
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
minifyCSS: true,
minifyJS: true,
},
}),
].filter(plugin => !!plugin),
};