Skip to content

Commit

Permalink
feat: support for SWC experimental plugins (#1796)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Mar 12, 2024
1 parent c280511 commit 9c1366a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coverage/
doc_build/
playwright-report/
tsconfig.tsbuildinfo
.swc

.vscode/**/*
!.vscode/settings.json
Expand Down
36 changes: 36 additions & 0 deletions e2e/cases/swc-plugin/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect, test } from '@playwright/test';
import { dev, build, gotoPage } from '@e2e/helper';

// TODO: https://github.com/web-infra-dev/rspack/issues/5921
test.skip('should run swc warm plugin correctly in dev mode', async ({
page,
}) => {
const rsbuild = await dev({
cwd: __dirname,
});

const msgPromise = page.waitForEvent('console');
await gotoPage(page, rsbuild);

const msg = await msgPromise;
expect(await msg.args()[0].jsonValue()).toEqual('this is error');

await rsbuild.close();
});

test.skip('should run swc warm plugin correctly in production build', async ({
page,
}) => {
const rsbuild = await build({
cwd: __dirname,
runServer: true,
});

const msgPromise = page.waitForEvent('console');
await gotoPage(page, rsbuild);

const msg = await msgPromise;
expect(await msg.args()[0].jsonValue()).toEqual('this is error');

await rsbuild.close();
});
8 changes: 8 additions & 0 deletions e2e/cases/swc-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"private": true,
"name": "@e2e/swc-plugin",
"version": "1.0.0",
"dependencies": {
"@swc/plugin-remove-console": "^1.5.117"
}
}
20 changes: 20 additions & 0 deletions e2e/cases/swc-plugin/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
tools: {
swc: {
jsc: {
experimental: {
plugins: [
[
'@swc/plugin-remove-console',
{
exclude: ['error'],
},
],
],
},
},
},
},
});
3 changes: 3 additions & 0 deletions e2e/cases/swc-plugin/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log('this is log');
console.warn('this is warn');
console.error('this is error');
3 changes: 3 additions & 0 deletions packages/shared/src/types/rspack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export type BuiltinSwcLoaderOptions = {
[from: string]: [string];
};
preserveAllComments?: boolean;
experimental?: {
plugins?: Array<[string, Record<string, any>]>;
};
};
rspackExperiments?: {
relay?:
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c1366a

Please sign in to comment.