diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/url_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/url_plugin.rs index 5965ed70b026..c40c38be824b 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/url_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/url_plugin.rs @@ -26,7 +26,7 @@ impl JavascriptParserPlugin for URLPlugin { start, end, expr.span.real_lo(), - expr.span.hi().0, + expr.span.real_hi(), request.into(), Some(expr.span.into()), self.relative, diff --git a/packages/rspack/tests/configCases/asset-url/relative/index.css b/packages/rspack/tests/configCases/asset-url/relative/index.css new file mode 100644 index 000000000000..077f6dd7c017 --- /dev/null +++ b/packages/rspack/tests/configCases/asset-url/relative/index.css @@ -0,0 +1 @@ +a {} diff --git a/packages/rspack/tests/configCases/asset-url/relative/index.js b/packages/rspack/tests/configCases/asset-url/relative/index.js new file mode 100644 index 000000000000..157f1aecbba4 --- /dev/null +++ b/packages/rspack/tests/configCases/asset-url/relative/index.js @@ -0,0 +1,4 @@ +it("should compile", () => { + const url = new URL("./index.css?query=yes#fragment", import.meta.url).href; + expect(url).toBeDefined(); +}); diff --git a/packages/rspack/tests/configCases/asset-url/relative/webpack.config.js b/packages/rspack/tests/configCases/asset-url/relative/webpack.config.js new file mode 100644 index 000000000000..f12e35da224b --- /dev/null +++ b/packages/rspack/tests/configCases/asset-url/relative/webpack.config.js @@ -0,0 +1,16 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + mode: "development", + devtool: false, + output: { + assetModuleFilename: "[name][ext][query][fragment]", + publicPath: "public/" + }, + module: { + parser: { + javascript: { + url: "relative" + } + } + } +};