-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
100 lines (94 loc) · 2.28 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
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
const path = require('path');
const ENV = process.env.NODE_ENV;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const ROOT_DIR = path.resolve(__dirname);
const SRC_DIR = path.resolve(__dirname, 'app');
const BUILD_DIR = path.resolve(__dirname, 'docs');
const PLUGINS = [];
const PAGE_ENTRIES = {
index: path.resolve(SRC_DIR, 'index.js'),
};
if (ENV === 'development') {
PAGE_ENTRIES['webpack-dev-server'] = 'webpack/hot/dev-server';
}
PLUGINS.push(new HtmlWebpackPlugin({
inject: 'body',
template: '!!ejs!app/index.ejs',
filename: 'index.html',
chunks: ['index'],
chunksSortMode: 'dependency',
env: process.env,
}));
var webpackConfig = {
devtool: 'eval',
entry: PAGE_ENTRIES,
output: {
path: BUILD_DIR,
filename: '[name].[hash:8].js',
},
resolve: {
root: ROOT_DIR,
},
module: {
preLoaders: [
{
test: /\.jsx?$/,
loader: 'eslint',
include: SRC_DIR,
},
],
loaders: [
{
test: /\.css$/, // Only .css files
loader: 'style!css?localIdentName=[path][name]---[local]---[hash:base64:5]', // Run both loaders
},
{
test: /\.scss$/,
loader: 'style!css?module&camelCase&localIdentName=[local]-[hash:5]!sass',
},
{
test: /\.html$/,
loader: 'html',
},
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.(png|jpg|gif|woff|svg|eot|ttf|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=[name]-[hash:8].[ext]',
},
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {presets: ['react', 'es2015']}
// 'babel-loader' is also a legal name to reference
},
],
},
plugins: PLUGINS,
imageWebpackLoader: {
pngquant: {
quality: '65-90',
speed: 4,
},
},
};
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins = webpackConfig.plugins.concat([
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
},
}),
]);
}
module.exports = webpackConfig;