@@ -35,44 +35,39 @@ const GLOBALS = {
35
35
// -----------------------------------------------------------------------------
36
36
37
37
const config = {
38
+ context : path . join ( __dirname , '../src' ) ,
39
+
38
40
output : {
39
41
publicPath : '/' ,
40
42
sourcePrefix : ' ' ,
41
43
} ,
42
44
43
- cache : DEBUG ,
44
- debug : DEBUG ,
45
-
46
- stats : {
47
- colors : true ,
48
- reasons : DEBUG ,
49
- hash : VERBOSE ,
50
- version : VERBOSE ,
51
- timings : true ,
52
- chunks : VERBOSE ,
53
- chunkModules : VERBOSE ,
54
- cached : VERBOSE ,
55
- cachedAssets : VERBOSE ,
56
- } ,
57
-
58
- plugins : [
59
- new webpack . optimize . OccurenceOrderPlugin ( ) ,
60
- ] ,
61
-
62
- resolve : {
63
- extensions : [ '' , '.webpack.js' , '.web.js' , '.js' , '.jsx' , '.json' ] ,
64
- } ,
65
-
66
45
module : {
67
46
loaders : [
68
47
{
69
48
test : / \. j s x ? $ / ,
49
+ loader : 'babel-loader' ,
70
50
include : [
71
51
path . resolve ( __dirname , '../node_modules/react-routing/src' ) ,
72
52
path . resolve ( __dirname , '../src' ) ,
73
53
] ,
74
- loader : 'babel-loader' ,
75
- } , {
54
+ query : {
55
+ // https://github.com/babel/babel-loader#options
56
+ cacheDirectory : DEBUG ,
57
+
58
+ // https://babeljs.io/docs/usage/options/
59
+ babelrc : false ,
60
+ presets : [
61
+ 'react' ,
62
+ 'es2015' ,
63
+ 'stage-0' ,
64
+ ] ,
65
+ plugins : [
66
+ 'transform-runtime' ,
67
+ ] ,
68
+ } ,
69
+ } ,
70
+ {
76
71
test : / \. s c s s $ / ,
77
72
loaders : [
78
73
'isomorphic-style-loader' ,
@@ -88,26 +83,52 @@ const config = {
88
83
} ) } `,
89
84
'postcss-loader?parser=postcss-scss' ,
90
85
] ,
91
- } , {
86
+ } ,
87
+ {
92
88
test : / \. j s o n $ / ,
93
89
loader : 'json-loader' ,
94
- } , {
90
+ } ,
91
+ {
95
92
test : / \. t x t $ / ,
96
93
loader : 'raw-loader' ,
97
- } , {
94
+ } ,
95
+ {
98
96
test : / \. ( p n g | j p g | j p e g | g i f | s v g | w o f f | w o f f 2 ) $ / ,
99
97
loader : 'url-loader?limit=10000' ,
100
- } , {
98
+ } ,
99
+ {
101
100
test : / \. ( e o t | t t f | w a v | m p 3 ) $ / ,
102
101
loader : 'file-loader' ,
103
- } , {
102
+ } ,
103
+ {
104
104
test : / \. j a d e $ / ,
105
105
loader : 'jade-loader' ,
106
106
} ,
107
107
] ,
108
108
} ,
109
109
110
- postcss : function plugins ( bundler ) {
110
+ resolve : {
111
+ root : path . join ( __dirname , '../src' ) ,
112
+ modulesDirectories : [ 'node_modules' ] ,
113
+ extensions : [ '' , '.webpack.js' , '.web.js' , '.js' , '.jsx' , '.json' ] ,
114
+ } ,
115
+
116
+ cache : DEBUG ,
117
+ debug : DEBUG ,
118
+
119
+ stats : {
120
+ colors : true ,
121
+ reasons : DEBUG ,
122
+ hash : VERBOSE ,
123
+ version : VERBOSE ,
124
+ timings : true ,
125
+ chunks : VERBOSE ,
126
+ chunkModules : VERBOSE ,
127
+ cached : VERBOSE ,
128
+ cachedAssets : VERBOSE ,
129
+ } ,
130
+
131
+ postcss ( bundler ) {
111
132
return [
112
133
require ( 'postcss-import' ) ( { addDependencyTo : bundler } ) ,
113
134
require ( 'precss' ) ( ) ,
@@ -121,51 +142,75 @@ const config = {
121
142
// -----------------------------------------------------------------------------
122
143
123
144
const clientConfig = extend ( true , { } , config , {
124
- entry : './src/client.js' ,
145
+ entry : './client.js' ,
146
+
125
147
output : {
126
148
path : path . join ( __dirname , '../build/public' ) ,
127
149
filename : DEBUG ? '[name].js?[hash]' : '[name].[hash].js' ,
150
+ chunkFilename : DEBUG ? '[name].[id].js?[hash]' : '[name].[id].[hash].js' ,
128
151
} ,
129
152
130
- // Choose a developer tool to enhance debugging
131
- // http://webpack.github.io/docs/configuration.html#devtool
132
- devtool : DEBUG ? 'cheap-module-eval-source-map' : false ,
153
+ target : 'web' ,
154
+
133
155
plugins : [
134
- ...config . plugins ,
156
+
157
+ // Define free variables
158
+ // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
135
159
new webpack . DefinePlugin ( { ...GLOBALS , 'process.env.BROWSER' : true } ) ,
160
+
161
+ // Emit a file with assets paths
162
+ // https://github.com/sporto/assets-webpack-plugin#options
136
163
new AssetsPlugin ( {
137
164
path : path . join ( __dirname , '../build' ) ,
138
165
filename : 'assets.js' ,
139
166
processOutput : x => `module.exports = ${ JSON . stringify ( x ) } ;` ,
140
167
} ) ,
141
- ...( ! DEBUG ? [
168
+
169
+ ...( DEBUG ? [ ] : [
170
+
171
+ // Search for equal or similar files and deduplicate them in the output
172
+ // https://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
142
173
new webpack . optimize . DedupePlugin ( ) ,
174
+
175
+ // Assign the module and chunk ids by occurrence count
176
+ // https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
177
+ new webpack . optimize . OccurenceOrderPlugin ( true ) ,
178
+
179
+ // Minimize all JavaScript output of chunks
180
+ // https://github.com/mishoo/UglifyJS2#compressor-options
143
181
new webpack . optimize . UglifyJsPlugin ( {
144
182
compress : {
145
- // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
146
- screw_ie8 : true ,
147
-
148
- // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
183
+ screw_ie8 : true , // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
149
184
warnings : VERBOSE ,
150
185
} ,
151
186
} ) ,
187
+
188
+ // A plugin for a more aggressive chunk merging strategy
189
+ // https://webpack.github.io/docs/list-of-plugins.html#aggressivemergingplugin
152
190
new webpack . optimize . AggressiveMergingPlugin ( ) ,
153
- ] : [ ] ) ,
191
+ ] ) ,
154
192
] ,
193
+
194
+ // Choose a developer tool to enhance debugging
195
+ // http://webpack.github.io/docs/configuration.html#devtool
196
+ devtool : DEBUG ? 'cheap-module-eval-source-map' : false ,
155
197
} ) ;
156
198
157
199
//
158
200
// Configuration for the server-side bundle (server.js)
159
201
// -----------------------------------------------------------------------------
160
202
161
203
const serverConfig = extend ( true , { } , config , {
162
- entry : './src/server.js' ,
204
+ entry : './server.js' ,
205
+
163
206
output : {
164
- path : '. /build',
207
+ path : path . join ( __dirname , '.. /build') ,
165
208
filename : 'server.js' ,
166
209
libraryTarget : 'commonjs2' ,
167
210
} ,
211
+
168
212
target : 'node' ,
213
+
169
214
externals : [
170
215
/ ^ \. \/ a s s e t s $ / ,
171
216
function filter ( context , request , cb ) {
@@ -176,6 +221,19 @@ const serverConfig = extend(true, {}, config, {
176
221
cb ( null , Boolean ( isExternal ) ) ;
177
222
} ,
178
223
] ,
224
+
225
+ plugins : [
226
+
227
+ // Define free variables
228
+ // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
229
+ new webpack . DefinePlugin ( { ...GLOBALS , 'process.env.BROWSER' : false } ) ,
230
+
231
+ // Adds a banner to the top of each generated chunk
232
+ // https://webpack.github.io/docs/list-of-plugins.html#bannerplugin
233
+ new webpack . BannerPlugin ( 'require("source-map-support").install();' ,
234
+ { raw : true , entryOnly : false } ) ,
235
+ ] ,
236
+
179
237
node : {
180
238
console : false ,
181
239
global : false ,
@@ -184,13 +242,8 @@ const serverConfig = extend(true, {}, config, {
184
242
__filename : false ,
185
243
__dirname : false ,
186
244
} ,
245
+
187
246
devtool : 'source-map' ,
188
- plugins : [
189
- ...config . plugins ,
190
- new webpack . DefinePlugin ( { ...GLOBALS , 'process.env.BROWSER' : false } ) ,
191
- new webpack . BannerPlugin ( 'require("source-map-support").install();' ,
192
- { raw : true , entryOnly : false } ) ,
193
- ] ,
194
247
} ) ;
195
248
196
249
export default [ clientConfig , serverConfig ] ;
0 commit comments