forked from gabrielbull/react-router-server-complex-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
65 lines (54 loc) · 1.62 KB
/
Copy pathwebpack.config.js
File metadata and controls
65 lines (54 loc) · 1.62 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
import path from 'path';
import fs from 'fs';
import webpack from 'webpack'
import StatsPlugin from 'stats-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
const nodeModules = {};
fs.readdirSync(path.join(__dirname, 'node_modules'))
.filter(x => ['.bin'].indexOf(x) === -1)
.forEach(mod => nodeModules[mod] = `commonjs ${mod}`);
const extractTextPlugin = new ExtractTextPlugin('[name].css');
extractTextPlugin.options.allChunks = true;
const config = server => ({
entry: {
app: path.join(__dirname, 'src', (server ? 'app.js' : 'client.js'))
},
output:{
path: server ? path.join(__dirname, 'build', 'server') : path.join(__dirname, 'build', 'public'),
filename: '[name].js',
chunkFilename: '[id].[hash].js',
publicPath: '/',
libraryTarget: (server ? 'commonjs2' : 'var')
},
externals: (server ? nodeModules : {}),
//devtool: 'source-map',
...(server ? {target: 'node'} : {}),
resolve: {
extensions: ['.js', '.jsx']
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{ test: /\.css$/, loader: extractTextPlugin.extract(['css-loader']) },
{ test: /\.(gif|png|jpg)$/, loader: 'file-loader' }
]
},
plugins: [
new StatsPlugin('stats.json', {
chunkModules: true,
exclude: [/node_modules/]
}),
extractTextPlugin,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
});
module.exports = [config(true), config(false)];