File tree Expand file tree Collapse file tree
concatenation-hmr-bailout Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import html from "./page.html" ;
2+
3+ it ( "should keep an HTML module out of concatenation when HMR is enabled" , ( ) => {
4+ expect ( html ) . toContain ( "<p>hmr page</p>" ) ;
5+ } ) ;
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html > < body > < p > hmr page</ p > </ body > </ html >
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const { HotModuleReplacementPlugin } = require ( "../../../../" ) ;
4+
5+ /** @type {import("../../../../").Configuration } */
6+ module . exports = {
7+ target : "web" ,
8+ mode : "production" ,
9+ module : {
10+ rules : [
11+ {
12+ test : / \. h t m l $ / ,
13+ type : "html"
14+ }
15+ ]
16+ } ,
17+ optimization : {
18+ minimize : false ,
19+ // HMR wires self-accept against a per-module `module.hot`, so an HTML
20+ // module merged into a shared scope would patch the wrong module id —
21+ // the generator has to refuse concatenation for it.
22+ concatenateModules : true
23+ } ,
24+ plugins : [ new HotModuleReplacementPlugin ( ) ] ,
25+ experiments : {
26+ html : true
27+ }
28+ } ;
Original file line number Diff line number Diff line change 1+ import "./style.css" ;
2+
3+ console . log ( "inline chunk hash" ) ;
Original file line number Diff line number Diff line change 1+ body { color : red; }
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ module . exports = {
4+ // The entry bundle is inlined into the page, so the assertions run from an
5+ // asset emitted beside it.
6+ findBundle ( ) {
7+ return [ "test.js" ] ;
8+ }
9+ } ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
3+
4+ it ( "should resolve an inlined chunk through the chunk hash when no content hash is set" , ( ) => {
5+ const html = fs
6+ . readFileSync ( path . resolve ( __dirname , "main.html" ) )
7+ . toString ( "utf-8" ) ;
8+ // Every sentinel resolved: none is left in the emitted page.
9+ expect ( html ) . not . toMatch ( / _ _ W E B P A C K _ H T M L _ I N L I N E _ _ / ) ;
10+ expect ( html ) . toMatch ( / < s t y l e > [ \s \S ] * c o l o r : ? r e d / ) ;
11+ expect ( html ) . toMatch ( / < s c r i p t > / ) ;
12+ } ) ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const fs = require ( "fs" ) ;
4+ const path = require ( "path" ) ;
5+ const webpack = require ( "../../../../" ) ;
6+
7+ /** @type {import("../../../../").WebpackPluginInstance } */
8+ const copyTest = {
9+ apply ( compiler ) {
10+ compiler . hooks . compilation . tap ( "Test" , ( compilation ) => {
11+ compilation . hooks . processAssets . tap (
12+ {
13+ name : "copy-test" ,
14+ stage : compiler . webpack . Compilation . PROCESS_ASSETS_STAGE_ADDITIONAL
15+ } ,
16+ ( ) => {
17+ compilation . emitAsset (
18+ "test.js" ,
19+ new webpack . sources . RawSource (
20+ fs . readFileSync ( path . resolve ( __dirname , "test.js" ) )
21+ )
22+ ) ;
23+ }
24+ ) ;
25+ } ) ;
26+ }
27+ } ;
28+
29+ /** @type {import("../../../../").Configuration } */
30+ module . exports = {
31+ target : "web" ,
32+ mode : "development" ,
33+ entry : { main : "./src.js" } ,
34+ output : {
35+ filename : "[name].js" ,
36+ htmlFilename : "main.html" ,
37+ // Inlining resolves each chunk through a sentinel carrying its hash; in
38+ // development the chunk carries no content hash, so the fallback runs.
39+ html : { inline : true }
40+ } ,
41+ experiments : {
42+ html : true ,
43+ css : true
44+ } ,
45+ plugins : [ copyTest ]
46+ } ;
You can’t perform that action at this time.
0 commit comments