From 0d7bfba0a570924fb154876736d80078fd888255 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Tue, 13 Aug 2024 11:50:02 +0800 Subject: [PATCH] fix: source map plugin module should enable by default --- .../src/options/raw_devtool.rs | 2 +- .../source-map/plugin-defaults/App.jsx | 3 ++ .../source-map/plugin-defaults/index.js | 13 ++++++++ .../plugin-defaults/rspack.config.js | 32 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/App.jsx create mode 100644 packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/rspack.config.js diff --git a/crates/rspack_binding_options/src/options/raw_devtool.rs b/crates/rspack_binding_options/src/options/raw_devtool.rs index 615b202181c..5f72d67dc57 100644 --- a/crates/rspack_binding_options/src/options/raw_devtool.rs +++ b/crates/rspack_binding_options/src/options/raw_devtool.rs @@ -149,7 +149,7 @@ impl From for SourceMapDevToolPluginOptions { no_sources, public_path: opts.public_path, module_filename_template, - module: opts.module.unwrap_or(false), + module: opts.module.unwrap_or(true), source_root: opts.source_root, test, } diff --git a/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/App.jsx b/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/App.jsx new file mode 100644 index 00000000000..cc96427c908 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/App.jsx @@ -0,0 +1,3 @@ +export function App() { + return
Hello Rspack!
; +} diff --git a/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/index.js b/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/index.js new file mode 100644 index 00000000000..ca70244f58f --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/index.js @@ -0,0 +1,13 @@ +require("./App"); + +it("`module` should be enabled by default", async () => { + const path = require("path"); + const fs = require("fs"); + + const source = fs.readFileSync(__filename + ".map", "utf-8"); + const app = fs.readFileSync(path.resolve(CONTEXT, "./App.jsx"), "utf-8"); + const map = JSON.parse(source); + const appSourceIndex = map.sources.indexOf("webpack:///./App.jsx") + expect(appSourceIndex).toBeGreaterThanOrEqual(0); + expect(map.sourcesContent[appSourceIndex]).toEqual(app); +}); diff --git a/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/rspack.config.js b/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/rspack.config.js new file mode 100644 index 00000000000..e758746f101 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/source-map/plugin-defaults/rspack.config.js @@ -0,0 +1,32 @@ +const rspack = require("@rspack/core"); +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + devtool: false, + resolve: { + extensions: ["...", ".ts", ".tsx", ".jsx"] + }, + module: { + rules: [ + { + test: /\.jsx$/, + loader: "builtin:swc-loader", + options: { + jsc: { + parser: { + syntax: "ecmascript", + jsx: true + } + } + } + } + ] + }, + plugins: [ + new rspack.DefinePlugin({ + CONTEXT: JSON.stringify(__dirname) + }), + new rspack.SourceMapDevToolPlugin({ + filename: '[file].map[query]', + }), + ] +};