-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76112b7
commit 11d99c0
Showing
6 changed files
with
222 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
console.log("One."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
console.log("Two."); |
85 changes: 85 additions & 0 deletions
85
test/fixtures/lazy-compilation-multiple-entries/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"use strict"; | ||
|
||
const webpack = require("webpack"); | ||
|
||
const isWebpack5 = webpack.version.startsWith("5"); | ||
|
||
const oneHTMLContent = ` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset='UTF-8'> | ||
<title>test</title> | ||
<script src="one.js"></script> | ||
</head> | ||
<body></body> | ||
</html> | ||
`; | ||
const twoHTMLContent = ` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset='UTF-8'> | ||
<title>test</title> | ||
<script src="two.js"></script> | ||
</head> | ||
<body></body> | ||
</html> | ||
`; | ||
|
||
module.exports = { | ||
devtool: false, | ||
mode: "development", | ||
context: __dirname, | ||
stats: "none", | ||
entry: { | ||
one: "./one.js", | ||
two: "./two.js", | ||
}, | ||
output: { | ||
path: "/", | ||
}, | ||
experiments: { | ||
lazyCompilation: true, | ||
}, | ||
infrastructureLogging: isWebpack5 | ||
? { | ||
level: "info", | ||
stream: { | ||
write: () => {}, | ||
}, | ||
} | ||
: { | ||
level: "info", | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
const pluginName = "html-generator-plugin-test"; | ||
const oneFilename = "test-one.html"; | ||
const twoFilename = "test-two.html"; | ||
|
||
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { | ||
const { RawSource } = compiler.webpack.sources; | ||
|
||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: pluginName, | ||
stage: | ||
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, | ||
}, | ||
() => { | ||
const oneSource = new RawSource(oneHTMLContent); | ||
|
||
compilation.emitAsset(oneFilename, oneSource); | ||
|
||
const twoSource = new RawSource(twoHTMLContent); | ||
|
||
compilation.emitAsset(twoFilename, twoSource); | ||
} | ||
); | ||
}); | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
console.log("Hey."); |
66 changes: 66 additions & 0 deletions
66
test/fixtures/lazy-compilation-single-entry/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use strict"; | ||
|
||
const webpack = require("webpack"); | ||
|
||
const isWebpack5 = webpack.version.startsWith("5"); | ||
|
||
const HTMLContent = ` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset='UTF-8'> | ||
<title>test</title> | ||
<script src="main.js"></script> | ||
</head> | ||
<body></body> | ||
</html> | ||
`; | ||
|
||
module.exports = { | ||
devtool: false, | ||
mode: "development", | ||
context: __dirname, | ||
stats: "none", | ||
entry: "./entry.js", | ||
output: { | ||
path: "/", | ||
}, | ||
experiments: { | ||
lazyCompilation: true, | ||
}, | ||
infrastructureLogging: isWebpack5 | ||
? { | ||
level: "info", | ||
stream: { | ||
write: () => {}, | ||
}, | ||
} | ||
: { | ||
level: "info", | ||
}, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
const pluginName = "html-generator-plugin-test"; | ||
const filename = "test.html"; | ||
|
||
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { | ||
const { RawSource } = compiler.webpack.sources; | ||
|
||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: pluginName, | ||
stage: | ||
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, | ||
}, | ||
() => { | ||
const source = new RawSource(HTMLContent); | ||
|
||
compilation.emitAsset(filename, source); | ||
} | ||
); | ||
}); | ||
}, | ||
}, | ||
], | ||
}; |