This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace runtime's chunk manifest with lookup
- Loading branch information
1 parent
401e202
commit 581d0eb
Showing
2 changed files
with
59 additions
and
4 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,52 @@ | ||
import test from "ava"; | ||
|
||
import ChunkManifestPlugin from "../src/chunk-manifest-webpack-plugin"; | ||
|
||
test.cb("replace runtime's chunk manifest with lookup", t => { | ||
const chunkIdVariableName = "a-chunk-id-variable"; | ||
const manifestVariable = "manifest-variable"; | ||
const placeholder = `"__CHUNK_MANIFEST__"`; | ||
|
||
const runtimeSource = [ | ||
"runtime-source-start", | ||
placeholder, | ||
";", | ||
"runtime-source-end" | ||
]; | ||
|
||
let expected = [...runtimeSource]; | ||
expected[1] = `window["${manifestVariable}"][${chunkIdVariableName}]`; | ||
|
||
const compilationPluginEvent = (compilationEvent, ensure) => { | ||
if (compilationEvent === "require-ensure") { | ||
const updatedSource = ensure( | ||
runtimeSource.join(""), | ||
undefined, | ||
undefined, | ||
chunkIdVariableName | ||
); | ||
t.is(updatedSource, expected.join("")); | ||
t.end(); | ||
} | ||
}; | ||
|
||
const pluginEvent = (event, compile) => { | ||
if (event === "compilation") { | ||
const compilation = { | ||
mainTemplate: { | ||
plugin: compilationPluginEvent | ||
} | ||
}; | ||
compile(compilation); | ||
} | ||
}; | ||
|
||
const fakeCompiler = { plugin: pluginEvent }; | ||
|
||
const plugin = new ChunkManifestPlugin({ | ||
manifestVariable | ||
}); | ||
|
||
plugin.plugins = [{ apply: () => {} }]; | ||
plugin.apply(fakeCompiler); | ||
}); |