-
Notifications
You must be signed in to change notification settings - Fork 33
/
webpack.config.js
134 lines (126 loc) · 3.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict' // eslint-disable-line strict
const path = require('path')
const webpack = require('webpack')
const WebpackToolsPlugin = require('webpack-isomorphic-tools/plugin')
const webpackToolsConfig = require('./webpack.isomorphic.tools')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
// Globals
const NODE_ENV = process.env.NODE_ENV || 'development'
const __DEV__ = NODE_ENV !== 'production'
const __PROD__ = NODE_ENV === 'production'
const __SERVER__ = false
const __CLIENT__ = true
let config
if (__DEV__) {
config = {
context: path.join(__dirname, 'src'),
entry: {
app: [
'webpack-hot-middleware/client',
'react-hot-loader/patch',
'./client.js'
]
},
resolve: {
extensions: ['.js']
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['react', ['es2015', { modules: false }], 'stage-0'],
plugins: ['react-hot-loader/babel']
},
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
loaders: [
'style-loader',
'css-loader?modules&localIdentName=[local]__[hash:base64:4]&importLoaders=1&sourceMap',
'postcss-loader?sourceMap',
'sass-loader?sourceMap'
]
}
]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
__DEV__,
__PROD__,
__SERVER__,
__CLIENT__
}),
new WebpackToolsPlugin(webpackToolsConfig).development(__DEV__)
],
devtool: 'inline-source-map'
}
}
if (__PROD__) {
config = {
context: path.join(__dirname, 'src'),
entry: {
app: './client.js'
},
resolve: {
extensions: ['.js']
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.[chunkhash].js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['react', ['es2015', { modules: false }], 'stage-0']
},
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader?modules&localIdentName=[hash:base64:4]&importLoaders=1&sourceMap',
'postcss-loader?sourceMap',
'sass-loader?sourceMap'
]
})
}
]
},
plugins: [
new ExtractTextPlugin('app.[contenthash:20].css'),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__DEV__,
__PROD__,
__SERVER__,
__CLIENT__
}),
new WebpackToolsPlugin(webpackToolsConfig).development(__DEV__)
],
devtool: 'source-map'
}
}
module.exports = config