-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
executable file
·80 lines (76 loc) · 2.1 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
const config = require('./config')
const path = require('path')
const webpack = require('webpack')
const WriteFilePlugin = require('write-file-webpack-plugin')
const isDebug = !process.argv.includes('--production')
const isVerbose = process.argv.includes('--verbose') || process.argv.includes('-v')
const webpackConfig = {
debug: isDebug,
devtool: isDebug ? 'source-map' : false,
entry: [
'babel-polyfill',
config.dirs.src + '/client/index.js'
],
output: {
path: path.join(__dirname, config.dirs.dest),
filename: `bundle.js`,
publicPath: `http://localhost:3000/wp-content/themes/${config.themeName}`
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'standard',
exclude: /node_modules/
}
],
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}, {
test: /\.json$/,
loader: 'json-loader'
}
]
},
resolve: {
extensions: [
'',
'.js',
'.css'
],
root: [
path.join(__dirname, `${config.dirs.src}/client`)
]
},
stats: {
colors: true,
reasons: isDebug,
hash: isVerbose,
version: isVerbose,
timings: true,
chunks: isVerbose,
chunkModules: isVerbose,
cached: isVerbose,
cachedAssets: isVerbose
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': isDebug ? '"development"' : '"production"'
})
]
}
if (isDebug) {
webpackConfig.entry.unshift('react-hot-loader/patch', `webpack-hot-middleware/client?http://localhost:3000&reload=true`)
webpackConfig.plugins.push(new webpack.optimize.OccurenceOrderPlugin())
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin())
webpackConfig.plugins.push(new webpack.NoErrorsPlugin())
webpackConfig.plugins.push(new WriteFilePlugin())
} else {
webpackConfig.plugins.push(new webpack.optimize.DedupePlugin())
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: isVerbose } }))
webpackConfig.plugins.push(new webpack.optimize.AggressiveMergingPlugin())
}
module.exports = webpackConfig