-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
88 lines (81 loc) · 2.5 KB
/
webpack.config.js
File metadata and controls
88 lines (81 loc) · 2.5 KB
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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const values = require('postcss-modules-values');
const webConfig = require('./config/web-config');
const serverConfig = require('./config/server-config');
const styleLoaders = [
'style',
'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]&postcss',
'sass',
];
const prodStyleLoaders = styleLoaders.slice(1);
const webpackConfig = {
debug: serverConfig.DEBUG,
devtool: serverConfig.DEBUG ? 'cheap-module-eval-source-map' : 'source-map',
entry: ['./src/web/main.js'],
output: {
path: path.resolve(__dirname, './src/server/public'),
publicPath: serverConfig.HOT ?
`http://${serverConfig.HOSTNAME}:${serverConfig.PROXY_PORT}/public/` :
'/public/',
filename: serverConfig.DEBUG ? '[name].js' : '[name].[hash].js',
chunkFileName: '[id].js',
},
module: {
loaders: [{
test: /\.js$/,
include: __dirname,
exclude: /node_modules/,
loader: 'babel',
}, {
test: /\.scss$/,
include: __dirname,
exclude: /node_modules(?!\/normalize)/,
loader: serverConfig.DEBUG ? null : ExtractTextPlugin.extract('style', prodStyleLoaders),
loaders: serverConfig.DEBUG ? styleLoaders : null,
}, {
test: /\.json$/,
loader: 'json',
}, {
test: /\.(png|jpe?g|gif)$/,
include: __dirname,
exclude: /node_modules/,
loaders: ['file', 'image-webpack'],
}, {
test: /\.svg$/,
include: [__dirname, path.resolve(__dirname, 'assets')],
exclude: /node_modules/,
loader: 'babel!react-svg',
}],
},
postcss: [
values,
],
plugins: [
new ExtractTextPlugin('main.css', { allChunks: true }),
new HtmlWebpackPlugin({
template: './src/web/index.html.tmpl',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(webConfig),
}),
new webpack.NoErrorsPlugin(),
],
};
if (serverConfig.HOT) {
webpackConfig.entry.unshift('webpack-hot-middleware/client');
webpackConfig.plugins.unshift(new webpack.HotModuleReplacementPlugin());
}
if (serverConfig.NODE_ENV === 'production') {
webpackConfig.plugins.unshift(new webpack.optimize.DedupePlugin());
webpackConfig.plugins.unshift(new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
screw_ie8: true,
warnings: false,
},
}));
}
module.exports = webpackConfig;