forked from web-infra-dev/rspack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: should forward sourcemaps for refresh loaders (web-infra-dev#7872)
- Loading branch information
Showing
8 changed files
with
314 additions
and
14 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
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
9 changes: 9 additions & 0 deletions
9
packages/rspack-test-tools/tests/configCases/builtin-swc-loader/preact-refresh/index.jsx
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 @@ | ||
function component () { | ||
return <div></div> | ||
} | ||
|
||
it('should work with preact-refresh', () => { | ||
const fs = require("fs") | ||
let map = fs.readFileSync(__filename + ".map", "utf-8") | ||
expect(map).toContain(STUB) | ||
}) |
57 changes: 57 additions & 0 deletions
57
...es/rspack-test-tools/tests/configCases/builtin-swc-loader/preact-refresh/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,57 @@ | ||
const rspack = require("@rspack/core") | ||
const PreactRefreshPlugin = require("@rspack/plugin-preact-refresh"); | ||
const { ConcatSource, RawSource } = require("webpack-sources") | ||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
entry: "./index.jsx", | ||
mode: "development", | ||
resolve: { | ||
extensions: ["...", ".ts", ".tsx", ".jsx"] | ||
}, | ||
devtool: "source-map", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx$/, | ||
loader: "builtin:swc-loader", | ||
options: { | ||
jsc: { | ||
parser: { | ||
syntax: "ecmascript", | ||
jsx: true, | ||
sourceMap: true, | ||
}, | ||
transform: { | ||
react: { | ||
runtime: "classic", | ||
pragma: "React.createElement", | ||
pragmaFrag: "React.Fragment", | ||
throwIfNamespace: true, | ||
useBuiltins: false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new rspack.HotModuleReplacementPlugin(), | ||
new PreactRefreshPlugin(), | ||
new rspack.DefinePlugin({ | ||
STUB: JSON.stringify("<div></div>") | ||
}), | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("_", (compilation) => { | ||
compilation.hooks.processAssets.tap("_", (assets) => { | ||
compilation.updateAsset("bundle0.js",new ConcatSource( | ||
new RawSource("const self = globalThis;"), // mock self to NodeJs specific global object | ||
assets["bundle0.js"] | ||
)) | ||
}) | ||
}) | ||
} | ||
} | ||
] | ||
}; |
9 changes: 9 additions & 0 deletions
9
packages/rspack-test-tools/tests/configCases/builtin-swc-loader/react-refresh/index.jsx
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 @@ | ||
function component () { | ||
return <div></div> | ||
} | ||
|
||
it('should work with react refresh', () => { | ||
const fs = require("fs") | ||
let map = fs.readFileSync(__filename + ".map", "utf-8") | ||
expect(map).toContain(STUB) | ||
}) |
44 changes: 44 additions & 0 deletions
44
...ges/rspack-test-tools/tests/configCases/builtin-swc-loader/react-refresh/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,44 @@ | ||
const rspack = require("@rspack/core") | ||
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); | ||
/** @type {import("@rspack/core").Configuration} */ | ||
module.exports = { | ||
entry: "./index.jsx", | ||
mode: "development", | ||
resolve: { | ||
extensions: ["...", ".ts", ".tsx", ".jsx"] | ||
}, | ||
devtool: "source-map", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx$/, | ||
loader: "builtin:swc-loader", | ||
options: { | ||
jsc: { | ||
parser: { | ||
syntax: "ecmascript", | ||
jsx: true, | ||
sourceMap: true, | ||
}, | ||
transform: { | ||
react: { | ||
runtime: "classic", | ||
pragma: "React.createElement", | ||
pragmaFrag: "React.Fragment", | ||
throwIfNamespace: true, | ||
useBuiltins: false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new rspack.HotModuleReplacementPlugin(), | ||
new ReactRefreshPlugin(), | ||
new rspack.DefinePlugin({ | ||
STUB: JSON.stringify("<div></div>") | ||
}) | ||
] | ||
}; |
Oops, something went wrong.