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
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class ReactRefreshRspackPlugin {
or: [this.options.exclude!, [...runtimePaths]].filter(Boolean),
},
resourceQuery: this.options.resourceQuery,
dependency: {
// `new URL("static/sdk.js", import.meta.url)` the sdk.js is an asset module
// we shoudn't inject react refresh for asset module
not: ['url'],
},
use: ReactRefreshRspackPlugin.loader,
});
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/url/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'foo';
new URL('./sdk.js', import.meta.url);
1 change: 1 addition & 0 deletions test/fixtures/url/sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'foo';
22 changes: 21 additions & 1 deletion test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ const compileWithReactRefresh = (
callback: CompilationCallback,
) => {
let dist = path.join(fixturePath, 'dist');
let cjsEntry = path.join(fixturePath, 'index.js');
let mjsEntry = path.join(fixturePath, 'index.mjs');
let entry = fs.existsSync(cjsEntry) ? cjsEntry : mjsEntry;
rspack(
{
mode: 'development',
context: fixturePath,
entry: {
fixture: path.join(fixturePath, 'index.js'),
fixture: entry,
},
output: {
path: dist,
uniqueName,
assetModuleFilename: '[name][ext]',
},
plugins: [new ReactRefreshPlugin(refreshOptions)],
optimization: {
Expand Down Expand Up @@ -164,6 +168,22 @@ describe('react-refresh-rspack-plugin', () => {
);
});

it('should exclude url dependency when compiling', (done) => {
compileWithReactRefresh(
path.join(__dirname, 'fixtures/url'),
{},
(_, stats) => {
const json = stats!.toJson({ all: false, outputPath: true });
const asset = fs.readFileSync(
path.resolve(json.outputPath!, 'sdk.js'),
'utf-8',
);
expect(asset).not.toContain('function $RefreshReg$');
done();
},
);
});

it('should allow custom inject loader when compiling', (done) => {
expect(ReactRefreshPlugin.loader).toBe('builtin:react-refresh-loader');
compileWithReactRefresh(
Expand Down