-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a74ee52
commit 5cdaa16
Showing
8 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
e2e/cases/plugin-api/plugin-transform-import-module/index.test.ts
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,18 @@ | ||
import { build, rspackOnlyTest } from '@e2e/helper'; | ||
import { expect } from '@playwright/test'; | ||
|
||
rspackOnlyTest( | ||
'should allow plugin to transform code and call `importModule`', | ||
async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await rsbuild.unwrapOutputJSON(); | ||
const indexCss = Object.keys(files).find( | ||
(file) => file.includes('index') && file.endsWith('.css'), | ||
); | ||
|
||
expect(files[indexCss!].includes('#00f')).toBeTruthy(); | ||
}, | ||
); |
13 changes: 13 additions & 0 deletions
13
e2e/cases/plugin-api/plugin-transform-import-module/myPlugin.ts
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,13 @@ | ||
import { join } from 'node:path'; | ||
import type { RsbuildPlugin } from '@rsbuild/core'; | ||
|
||
export const myPlugin: RsbuildPlugin = { | ||
name: 'my-plugin', | ||
setup(api) { | ||
api.transform({ test: /\.css$/ }, async ({ code, importModule }) => { | ||
// @ts-expect-error TODO: Rspack type issue | ||
const { foo } = await importModule(join(__dirname, './src/foo.ts')); | ||
return code.replace('red', foo); | ||
}); | ||
}, | ||
}; |
5 changes: 5 additions & 0 deletions
5
e2e/cases/plugin-api/plugin-transform-import-module/rsbuild.config.ts
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,5 @@ | ||
import { myPlugin } from './myPlugin'; | ||
|
||
export default { | ||
plugins: [myPlugin], | ||
}; |
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 @@ | ||
export const foo = 'blue'; |
3 changes: 3 additions & 0 deletions
3
e2e/cases/plugin-api/plugin-transform-import-module/src/index.css
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,3 @@ | ||
body { | ||
color: red; | ||
} |
3 changes: 3 additions & 0 deletions
3
e2e/cases/plugin-api/plugin-transform-import-module/src/index.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,3 @@ | ||
import './index.css'; | ||
|
||
console.log('hello'); |
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
5cdaa16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open