Skip to content

Commit 785e0df

Browse files
authored
fix: narrow default node_modules exclude (#123)
1 parent 8cb43a0 commit 785e0df

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ new ReactRefreshPlugin({
119119
### exclude
120120

121121
- Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)
122-
- Default: `/node_modules/`
122+
- Default: `/[\\/]node_modules[\\/]/`
123123

124124
Exclude files from being processed by the plugin. The value is the same as the [rule.exclude](https://rspack.rs/config/module-rules#rulesexclude) option in Rspack.
125125

126126
```js
127127
new ReactRefreshPlugin({
128-
exclude: [/node_modules/, /some-other-module/],
128+
exclude: [/[\\/]node_modules[\\/]/, /some-other-module/],
129129
});
130130
```
131131

src/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type PluginOptions = {
2121
/**
2222
* Exclude files from being processed by the plugin.
2323
* The value is the same as the `rule.exclude` option in Rspack.
24-
* @default /node_modules/
24+
* @default /[\\/]node_modules[\\/]/
2525
* @see https://rspack.rs/config/module-rules#rulesexclude
2626
*/
2727
exclude?: RuleSetCondition | null;
@@ -95,7 +95,7 @@ export function normalizeOptions(
9595
options: PluginOptions,
9696
): NormalizedPluginOptions {
9797
d(options, 'test', /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/);
98-
d(options, 'exclude', /node_modules/i);
98+
d(options, 'exclude', /[\\/]node_modules[\\/]/);
9999
d(options, 'library');
100100
d(options, 'forceEnable', false);
101101
d(options, 'injectLoader', true);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import 'foo';
2+
3+
export default 'contains-node_modules-name';

test/test.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ describe('react-refresh-rspack-plugin', () => {
160160
expect(fixture).toContain('function $RefreshReg$');
161161
});
162162

163+
it('should include paths that only contain node_modules in the name', async () => {
164+
const {
165+
outputs: { fixture },
166+
} = await compileWithReactRefresh(
167+
path.join(import.meta.dirname, 'fixtures/contains-node_modules-name'),
168+
{},
169+
);
170+
expect(fixture).toContain('function $RefreshReg$');
171+
});
172+
163173
it('should add library to make sure work in Micro-Frontend', async () => {
164174
const {
165175
outputs: { reactRefresh },

0 commit comments

Comments
 (0)