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
17 changes: 17 additions & 0 deletions e2e/cases/plugin-babel/import-attributes-text-script/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { expect, test } from '@e2e/helper';
import { pluginBabel } from '@rsbuild/plugin-babel';

test('should keep text imports unchanged with Babel include', async ({ page, buildPreview }) => {
await buildPreview({
config: {
plugins: [pluginBabel({ include: /src/ })],
},
});

expect(await page.evaluate('window.scriptText')).toBe(
readFileSync(join(import.meta.dirname, 'src/text.ts'), 'utf-8'),
);
expect(await page.evaluate('window.scriptValue')).toBe('text fixture');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { value } from './text.ts';
import scriptText from './text.ts' with { type: 'text' };

window.scriptText = scriptText;
window.scriptValue = value;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value: string = 'text fixture';
1 change: 1 addition & 0 deletions packages/plugin-babel/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const pluginBabel = (options: PluginBabelOptions = {}): RsbuildPlugin =>

const loader = rule
.test(SCRIPT_REGEX)
.with({ type: { not: 'text' } })
.use(CHAIN_ID.USE.BABEL)
.loader(BABEL_LOADER_PATH)
Comment on lines 142 to 146
.options(babelOptions);
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-babel/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ exports[`plugins/babel > should allow to add multiple babel rules 1`] = `
},
},
],
"with": {
"type": {
"not": "text",
},
},
},
{
"include": [
Expand Down Expand Up @@ -252,6 +257,11 @@ exports[`plugins/babel > should allow to add multiple babel rules 1`] = `
},
},
],
"with": {
"type": {
"not": "text",
},
},
},
]
`;
Expand Down
Loading