-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
121 lines (115 loc) · 3.01 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const _ = require('lodash');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const babel = require('./package').babel;
const config = {
context: `${__dirname}/src`,
entry: {
app: [
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/only-dev-server',
'./client',
],
},
output: {
path: `${__dirname}/build`,
filename: '/[name].js',
},
module: {
loaders: [
{
test: /\.jsx?$/,
include: `${__dirname}/src`,
loader: 'babel',
query: {
presets: babel.presets,
plugins: babel.plugins,
},
},
{
test: /\.css$/,
loader: [
'style',
'css?modules&importLoaders=1&localIdentName=[path]_[name]_[local]_[hash:base64:5]',
'postcss',
].join('!'),
},
{
test: /\.json$/,
loaders: 'json',
},
],
},
resolve: {
root: `${__dirname}/src`,
extensions: ['', '.js', '.jsx', '.css', '.json'],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
new webpack.ProvidePlugin({
Promise: 'imports?this=>global!exports?global.Promise!es6-promise',
fetch: 'imports?this=>global!exports?global.fetch!whatwg-fetch',
}),
new CleanWebpackPlugin(['build'], { root: __dirname, verbose: false }),
new HtmlWebpackPlugin({
template: './template/index.ejs',
inject: 'body',
title: 'Kit',
}),
],
postcss: () => [
autoprefixer,
],
};
if (process.env.NODE_ENV === 'production') {
const index = _.findIndex(config.module.loaders, ['test', /\.css$/]);
config.module.loaders[index] = {
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style',
'css?minimize&modules&importLoaders=1&localIdentName=[hash:base64:5]!postcss'
),
};
config.plugins.push(new ExtractTextPlugin('/[name]-[contenthash].min.css', {
allChunks: true,
}));
config.plugins.push(new webpack.optimize.DedupePlugin());
config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin(true));
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
},
comments: false,
sourceMap: false,
}));
config.output.filename = '/[name]-[hash].min.js';
config.output.hash = true;
config.entry.app = [_.last(config.entry.app)];
} else {
config.devtool = 'source-map';
config.devServer = {
contentBase: `${__dirname}/build`,
historyApiFallback: true,
hot: true,
stats: {
colors: true,
timings: true,
reasons: false,
hash: false,
version: false,
chunks: false,
chunkModules: false,
cached: false,
cachedAssets: false,
},
};
}
module.exports = config;