-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: module executor should use separate plugin_driver
- Loading branch information
Showing
18 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
9 changes: 2 additions & 7 deletions
9
crates/rspack_binding_options/src/plugins/buildtime_plugins.rs
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 |
---|---|---|
@@ -1,15 +1,10 @@ | ||
use rspack_core::{BoxPlugin, ChunkLoading, ChunkLoadingType, PluginExt}; | ||
use rspack_core::{BoxPlugin, PluginExt}; | ||
use rspack_plugin_javascript::JsPlugin; | ||
use rspack_plugin_runtime::{ | ||
CommonJsChunkLoadingPlugin, RuntimePlugin, StartupChunkDependenciesPlugin, | ||
}; | ||
use rspack_plugin_runtime::RuntimePlugin; | ||
|
||
pub fn buildtime_plugins() -> Vec<BoxPlugin> { | ||
vec![ | ||
RuntimePlugin::default().boxed(), | ||
JsPlugin::default().boxed(), | ||
// StartupChunkDependenciesPlugin::new(ChunkLoading::Enable(ChunkLoadingType::Require), false) | ||
// .boxed(), | ||
// CommonJsChunkLoadingPlugin::new(false).boxed(), | ||
] | ||
} |
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
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
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
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
2 changes: 2 additions & 0 deletions
2
...es/rspack-test-tools/tests/configCases/runtime/add-runtime-module-with-import-module/a.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,2 @@ | ||
import(/* webpackChunkName: "chunk-b" */'./b'); | ||
export default "a"; |
2 changes: 2 additions & 0 deletions
2
...es/rspack-test-tools/tests/configCases/runtime/add-runtime-module-with-import-module/b.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,2 @@ | ||
import(/* webpackChunkName: "chunk-c" */'./c'); | ||
export default "b"; |
1 change: 1 addition & 0 deletions
1
...es/rspack-test-tools/tests/configCases/runtime/add-runtime-module-with-import-module/c.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 @@ | ||
export default "c"; |
1 change: 1 addition & 0 deletions
1
...t-tools/tests/configCases/runtime/add-runtime-module-with-import-module/execute-module.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 @@ | ||
export default 1 |
Empty file.
9 changes: 9 additions & 0 deletions
9
...spack-test-tools/tests/configCases/runtime/add-runtime-module-with-import-module/index.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,9 @@ | ||
import v from './imported-module' | ||
|
||
import(/* webpackChunkName: "chunk-a" */'./a'); | ||
|
||
it("should inject mock runtime module", async function () { | ||
expect(v).toBe(1) | ||
expect(typeof __webpack_require__.mock).toBe("function"); | ||
expect(__webpack_require__.mock("chunk-a")).toBe("chunk-a.bundle0.js"); | ||
}); |
7 changes: 7 additions & 0 deletions
7
...pack-test-tools/tests/configCases/runtime/add-runtime-module-with-import-module/loader.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,7 @@ | ||
const path = require('path') | ||
|
||
module.exports = async function loader() { | ||
const callback = this.async() | ||
const result = await this.importModule(path.resolve(__dirname, './execute-module.js')) | ||
callback(null, `export default ${result.default}`) | ||
} |
63 changes: 63 additions & 0 deletions
63
...st-tools/tests/configCases/runtime/add-runtime-module-with-import-module/rspack.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,63 @@ | ||
const { RuntimeModule, RuntimeGlobals } = require("@rspack/core"); | ||
|
||
class MockRuntimeModule extends RuntimeModule { | ||
constructor() { | ||
super("mock"); | ||
} | ||
|
||
generate(compilation) { | ||
const chunkIdToName = this.chunk.getChunkMaps(false).name; | ||
const chunkNameToId = Object.fromEntries( | ||
Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [ | ||
chunkName, | ||
chunkId, | ||
]), | ||
); | ||
|
||
return ` | ||
__webpack_require__.mock = function(chunkId) { | ||
chunkId = (${JSON.stringify( | ||
chunkNameToId, | ||
)})[chunkId]||chunkId; | ||
return ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId); | ||
}; | ||
`; | ||
} | ||
} | ||
|
||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
entry: "./index.js", | ||
mode: "development", | ||
devtool: false, | ||
module: { | ||
rules: [ | ||
{ test: /imported-module\.js/, use: ['./loader']} | ||
] | ||
}, | ||
optimization: { | ||
minimize: false, | ||
sideEffects: false, | ||
concatenateModules: false, | ||
usedExports: false, | ||
innerGraph: false, | ||
providedExports: false | ||
}, | ||
plugins: [ | ||
compiler => { | ||
compiler.hooks.thisCompilation.tap( | ||
"MockRuntimePlugin", | ||
(compilation) => { | ||
compilation.hooks.runtimeRequirementInTree.tap("MockRuntimePlugin", (chunk, set) => { | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new MockRuntimeModule(chunk) | ||
); | ||
}) | ||
} | ||
); | ||
} | ||
], | ||
}; |
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