@@ -48,6 +48,31 @@ module.exports = (api, options) => {
48
48
// HTML plugin
49
49
const resolveClientEnv = require ( '../util/resolveClientEnv' )
50
50
51
+ // #1669 html-webpack-plugin's default sort uses toposort which cannot
52
+ // handle cyclic deps in certain cases. Monkey patch it to handle the case
53
+ // before we can upgrade to its 4.0 version (incompatible with preload atm)
54
+ const chunkSorters = require ( 'html-webpack-plugin/lib/chunksorter' )
55
+ const depSort = chunkSorters . dependency
56
+ chunkSorters . auto = chunkSorters . dependency = ( chunks , ...args ) => {
57
+ try {
58
+ return depSort ( chunks , ...args )
59
+ } catch ( e ) {
60
+ // fallback to a manual sort if that happens...
61
+ return chunks . sort ( ( a , b ) => {
62
+ // make sure user entry is loaded last so user CSS can override
63
+ // vendor CSS
64
+ if ( a . id === 'app' ) {
65
+ return 1
66
+ } else if ( b . id === 'app' ) {
67
+ return - 1
68
+ } else if ( a . entry !== b . entry ) {
69
+ return b . entry ? - 1 : 1
70
+ }
71
+ return 0
72
+ } )
73
+ }
74
+ }
75
+
51
76
const htmlOptions = {
52
77
templateParameters : ( compilation , assets , pluginOptions ) => {
53
78
// enhance html-webpack-plugin's built in template params
@@ -81,18 +106,6 @@ module.exports = (api, options) => {
81
106
removeScriptTypeAttributes : true
82
107
// more options:
83
108
// https://github.com/kangax/html-minifier#options-quick-reference
84
- } ,
85
- // #1669 default sort mode uses toposort which cannot handle cyclic deps
86
- // in certain cases, and in webpack 4, chunk order in HTML doesn't
87
- // matter anyway
88
- chunksSortMode : ( a , b ) => {
89
- if ( a . entry !== b . entry ) {
90
- // make sure entry is loaded last so user CSS can override
91
- // vendor CSS
92
- return b . entry ? - 1 : 1
93
- } else {
94
- return 0
95
- }
96
109
}
97
110
} )
98
111
0 commit comments