@@ -409,25 +409,18 @@ export function createExtraRules(
409409
410410/**
411411 * Plugin for HtmlPlugin which inlines the Webpack runtime code and chunk
412- * manifest into the HTML in a <script> tag before other emitted asssets are
413- * injected by HtmlPlugin itself.
412+ * manifest into its <script> tag.
414413 */
415414function inlineRuntimePlugin ( ) {
416415 this . hooks . compilation . tap ( 'inlineRuntimePlugin' , compilation => {
417- compilation . hooks . htmlWebpackPluginBeforeHtmlProcessing . tapAsync ( 'inlineRuntimePlugin' , ( data , cb ) => {
418- Object . keys ( compilation . assets ) . forEach ( key => {
419- if ( ! / ^ r u n t i m e \. [ a - z \d ] + \. j s $ / . test ( key ) ) return
420- let { children} = compilation . assets [ key ]
416+ HtmlPlugin . getHooks ( compilation ) . alterAssetTags . tapAsync ( 'inlineRuntimePlugin' , ( data , cb ) => {
417+ Object . keys ( compilation . assets ) . forEach ( assetName => {
418+ if ( ! / ^ r u n t i m e \. [ a - z \d ] + \. j s $ / . test ( assetName ) ) return
419+ let { children} = compilation . assets [ assetName ]
421420 if ( children && children [ 0 ] ) {
422- data . html = data . html . replace (
423- / ^ ( \s * ) < \/ b o d y > / m,
424- `$1<script>${ children [ 0 ] . _value } </script>\n$1</body>`
425- )
426- // Remove the runtime from HtmlPlugin's assets to prevent a <script>
427- // tag being created for it.
428- var runtimeIndex = data . assets . js . indexOf ( data . assets . publicPath + key )
429- data . assets . js . splice ( runtimeIndex , 1 )
430- delete data . assets . chunks . runtime
421+ let tag = data . assetTags . scripts . find ( tag => tag . attributes . src . endsWith ( assetName ) )
422+ delete tag . attributes . src
423+ tag . innerHTML = children [ 0 ] . _value
431424 }
432425 } )
433426 cb ( null , data )
@@ -557,7 +550,6 @@ export function createPlugins(
557550 // Generate an HTML file for web apps which pulls in generated resources
558551 if ( buildConfig . html ) {
559552 plugins . push ( new HtmlPlugin ( {
560- chunksSortMode : 'dependency' ,
561553 template : path . join ( __dirname , '../templates/webpack-template.html' ) ,
562554 ...buildConfig . html ,
563555 ...userConfig . html ,
0 commit comments