@@ -11,25 +11,38 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
11
11
import { ReactLoadablePlugin } from 'react-loadable/webpack' ;
12
12
import config from '../config' ;
13
13
14
- const ssr = yn ( process . env . SSR ) || false ;
15
- const isoPlugin = new IsoPlugin ( config . isomorphicConfig ) . development ( isDev ) ;
16
- const extractTextPlugin = new ExtractTextPlugin ( {
14
+ let ssr = yn ( process . env . SSR ) || false ;
15
+ let isoPlugin = new IsoPlugin ( config . isomorphicConfig ) . development ( isDev ) ;
16
+ let extractTextPlugin = new ExtractTextPlugin ( {
17
17
filename : isDev ? '[name].css' : '[name].[contenthash].css' ,
18
18
allChunks : true ,
19
19
disable : ssr
20
20
} ) ;
21
- const plugins = [
21
+
22
+ let plugins = [
22
23
isoPlugin ,
23
- new ReactLoadablePlugin ( {
24
- filename : path . join ( __dirname , '..' , 'react-loadable.json' )
25
- } ) ,
26
24
extractTextPlugin ,
27
25
new webpack . ContextReplacementPlugin ( / m o m e n t [ / \\ ] l o c a l e $ / , / e n | e s / ) ,
28
26
new webpack . DefinePlugin ( {
29
27
'process.env' : config . clientEnv
30
28
} )
31
29
] ;
32
30
31
+ let output = {
32
+ path : path . join ( __dirname , '..' , process . env . PUBLIC_OUTPUT_PATH ) ,
33
+ filename : '[name].bundle.js' ,
34
+ publicPath : process . env . PUBLIC_ASSET_PATH || '/'
35
+ } ;
36
+
37
+ // Enable dynamically imported code-splitting
38
+ if ( config . enableDynamicImports ) {
39
+ plugins . unshift ( new ReactLoadablePlugin ( {
40
+ filename : path . join ( __dirname , '..' , 'react-loadable.json' )
41
+ } ) ) ;
42
+
43
+ output . chunkFilename = '[name].bundle.js' ;
44
+ }
45
+
33
46
if ( process . env . ANALYZE ) {
34
47
plugins . push ( new BundleAnalyzerPlugin ( ) ) ;
35
48
}
@@ -39,12 +52,7 @@ export default {
39
52
entry : {
40
53
app : [ './client/index' ]
41
54
} ,
42
- output : {
43
- path : path . join ( __dirname , '..' , process . env . PUBLIC_OUTPUT_PATH ) ,
44
- filename : '[name].bundle.js' ,
45
- chunkFilename : '[name].bundle.js' ,
46
- publicPath : process . env . PUBLIC_ASSET_PATH || '/'
47
- } ,
55
+ output,
48
56
resolve : {
49
57
extensions : [ '.js' , '.jsx' , '.scss' ] ,
50
58
alias : mapValues ( config . clientResolvePaths , str =>
0 commit comments