Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/rspack_plugin_javascript/src/plugin/runtime_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ var module = ({module_cache}[moduleId] = {{"#,
let module_cache = runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE);
let intercept_module_execution =
runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION);
let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE);
let has_custom_runtime_module = compilation
.build_chunk_graph_artifact
.chunk_graph
Expand All @@ -167,6 +166,19 @@ var module = ({module_cache}[moduleId] = {{"#,
|| has_custom_runtime_module;
let need_module_defer =
runtime_requirements.contains(RuntimeGlobals::MAKE_DEFERRED_NAMESPACE_OBJECT);
let module_used = compilation
.build_chunk_graph_artifact
.chunk_graph
.get_chunk_entry_modules(chunk_ukey)
.iter()
.any(|module_identifier| {
ChunkGraph::get_module_runtime_requirements(
compilation,
*module_identifier,
chunk.runtime(),
)
.is_some_and(|requirements| requirements.contains(RuntimeGlobals::MODULE))
});
let use_require = require_function || intercept_module_execution || module_used;
let mut header: Vec<Cow<str>> = Vec::new();
let mut startup: Vec<Cow<str>> = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import logo from "./logo.svg";

export { logo };
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const {
experiments: { RslibPlugin },
} = require('@rspack/core');

/** @type {import("@rspack/core").Configuration} */
module.exports = {
target: 'node',
experiments: {
runtimeMode: 'rspack',
},
module: {
rules: [
{
test: /\.svg$/,
type: 'asset/resource',
},
],
},
output: {
iife: false,
library: {
type: 'commonjs-static',
},
},
plugins: [new RslibPlugin()],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require("fs");

/** @type {import("../../../..").TConfigCaseConfig} */
module.exports = {
afterExecute(options) {
const source = fs.readFileSync(options.output.path + "/bundle0.js", "utf-8");

expect(source).not.toContain("function __rspack_require");
expect(source).not.toContain("var __rspack_module_cache");
expect(source).not.toContain("__rspack_modules[moduleId]");
}
};
Loading