@@ -7,23 +7,6 @@ module.exports = (api, options) => {
77 return
88 }
99
10- // inject preload/prefetch to HTML
11- const PreloadPlugin = require ( '../webpack/PreloadPlugin' )
12- webpackConfig
13- . plugin ( 'preload' )
14- . use ( PreloadPlugin , [ {
15- rel : 'preload' ,
16- include : 'initial' ,
17- fileBlacklist : [ / \. m a p $ / , / h o t - u p d a t e \. j s $ / ]
18- } ] )
19-
20- webpackConfig
21- . plugin ( 'prefetch' )
22- . use ( PreloadPlugin , [ {
23- rel : 'prefetch' ,
24- include : 'asyncChunks'
25- } ] )
26-
2710 // HTML plugin
2811 const fs = require ( 'fs' )
2912 const htmlPath = api . resolve ( 'public/index.html' )
@@ -38,7 +21,33 @@ module.exports = (api, options) => {
3821 )
3922 ] )
4023
24+ // copy static assets in public/
25+ webpackConfig
26+ . plugin ( 'copy' )
27+ . use ( require ( 'copy-webpack-plugin' ) , [ [ {
28+ from : api . resolve ( 'public' ) ,
29+ to : api . resolve ( options . outputDir ) ,
30+ ignore : [ 'index.html' , '.DS_Store' ]
31+ } ] ] )
32+
4133 if ( process . env . NODE_ENV === 'production' ) {
34+ // inject preload/prefetch to HTML
35+ const PreloadPlugin = require ( '../webpack/PreloadPlugin' )
36+ webpackConfig
37+ . plugin ( 'preload' )
38+ . use ( PreloadPlugin , [ {
39+ rel : 'preload' ,
40+ include : 'initial' ,
41+ fileBlacklist : [ / \. m a p $ / , / h o t - u p d a t e \. j s $ / ]
42+ } ] )
43+
44+ webpackConfig
45+ . plugin ( 'prefetch' )
46+ . use ( PreloadPlugin , [ {
47+ rel : 'prefetch' ,
48+ include : 'asyncChunks'
49+ } ] )
50+
4251 // minify HTML
4352 webpackConfig
4453 . plugin ( 'html' )
@@ -54,64 +63,33 @@ module.exports = (api, options) => {
5463 chunksSortMode : 'dependency'
5564 } ) ] )
5665
57- // Code splitting configs for better long-term caching
58- // This needs to be updated when upgrading to webpack 4
59- const CommonsChunkPlugin = require ( 'webpack/lib/optimize/CommonsChunkPlugin' )
66+ // // Code splitting configs for better long-term caching
67+ // // This needs to be updated when upgrading to webpack 4
68+ // const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
6069
6170 if ( ! options . dll ) {
62- // extract vendor libs into its own chunk for better caching, since they
63- // are more likely to stay the same.
64- webpackConfig
65- . plugin ( 'split-vendor' )
66- . use ( CommonsChunkPlugin , [ {
67- name : 'vendor' ,
68- minChunks ( module ) {
69- // any required modules inside node_modules are extracted to vendor
70- return (
71- module . resource &&
72- / \. j s $ / . test ( module . resource ) &&
73- module . resource . indexOf ( `node_modules` ) > - 1
74- )
75- }
76- } ] )
77-
78- // extract webpack runtime and module manifest to its own file in order to
79- // prevent vendor hash from being updated whenever app bundle is updated
80- webpackConfig
81- . plugin ( 'split-manifest' )
82- . use ( CommonsChunkPlugin , [ {
83- name : 'manifest' ,
84- minChunks : Infinity
85- } ] )
71+ webpackConfig . optimization
72+ . set ( 'runtimeChunk' , true )
73+ . set ( 'splitChunks' , {
74+ chunks : 'all'
75+ } )
8676
8777 // inline the manifest chunk into HTML
8878 webpackConfig
8979 . plugin ( 'inline-manifest' )
9080 . use ( require ( '../webpack/InlineSourcePlugin' ) , [ {
91- include : / m a n i f e s t \. .* \. j s $ /
81+ include : / r u n t i m e ~ .* \. j s $ /
9282 } ] )
9383
9484 // since manifest is inlined, don't preload it anymore
9585 webpackConfig
9686 . plugin ( 'preload' )
9787 . tap ( ( [ options ] ) => {
98- options . fileBlacklist . push ( / m a n i f e s t \. .* \. j s $ / )
88+ options . fileBlacklist . push ( / r u n t i m e ~ .* \. j s $ / )
9989 return [ options ]
10090 } )
10191 }
10292
103- // This CommonsChunkPlugin instance extracts shared chunks from async
104- // chunks and bundles them in a separate chunk, similar to the vendor chunk
105- // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
106- webpackConfig
107- . plugin ( 'split-vendor-async' )
108- . use ( CommonsChunkPlugin , [ {
109- name : 'app' ,
110- async : 'vendor-async' ,
111- children : true ,
112- minChunks : 3
113- } ] )
114-
11593 // DLL
11694 if ( options . dll ) {
11795 const webpack = require ( 'webpack' )
@@ -142,15 +120,6 @@ module.exports = (api, options) => {
142120 } ] )
143121 . after ( 'preload' )
144122 }
145-
146- // copy static assets in public/
147- webpackConfig
148- . plugin ( 'copy' )
149- . use ( require ( 'copy-webpack-plugin' ) , [ [ {
150- from : api . resolve ( 'public' ) ,
151- to : api . resolve ( options . outputDir ) ,
152- ignore : [ 'index.html' , '.DS_Store' ]
153- } ] ] )
154123 }
155124 } )
156125}
0 commit comments