-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reference style modules as URL assets (#4016)
- Loading branch information
1 parent
a5a7361
commit 8594f32
Showing
21 changed files
with
293 additions
and
127 deletions.
There are no files selected for viewing
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,49 @@ | ||
import { build, rspackOnlyTest } from '@e2e/helper'; | ||
import { expect } from '@playwright/test'; | ||
|
||
rspackOnlyTest( | ||
'should allow to use `new URL` to reference styles as assets', | ||
async ({ page }) => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
page, | ||
}); | ||
|
||
const files = await rsbuild.unwrapOutputJSON(); | ||
const filenames = Object.keys(files); | ||
|
||
const test1 = filenames.find((filename) => | ||
filename.includes('dist/static/assets/test1.css'), | ||
); | ||
const test2 = filenames.find((filename) => | ||
filename.includes('dist/static/assets/test2.less'), | ||
); | ||
const test3 = filenames.find((filename) => | ||
filename.includes('dist/static/assets/test3.scss'), | ||
); | ||
const test4 = filenames.find((filename) => | ||
filename.includes('dist/static/assets/test4.styl'), | ||
); | ||
|
||
expect(test1).toBeDefined(); | ||
expect(test2).toBeDefined(); | ||
expect(test3).toBeDefined(); | ||
expect(test4).toBeDefined(); | ||
expect(files[test1!]).toContain('body{color:red}'); | ||
expect(files[test2!]).toContain('& .foo'); | ||
expect(files[test3!]).toContain('& .foo'); | ||
expect(files[test4!]).toContain('& .foo'); | ||
expect(await page.evaluate('window.test1')).toBe( | ||
`http://localhost:${rsbuild.port}/static/assets/test1.css`, | ||
); | ||
expect(await page.evaluate('window.test2')).toBe( | ||
`http://localhost:${rsbuild.port}/static/assets/test2.less`, | ||
); | ||
expect(await page.evaluate('window.test3')).toBe( | ||
`http://localhost:${rsbuild.port}/static/assets/test3.scss`, | ||
); | ||
expect(await page.evaluate('window.test4')).toBe( | ||
`http://localhost:${rsbuild.port}/static/assets/test4.styl`, | ||
); | ||
}, | ||
); |
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,11 @@ | ||
import { defineConfig } from '@rsbuild/core'; | ||
import { pluginLess } from '@rsbuild/plugin-less'; | ||
import { pluginSass } from '@rsbuild/plugin-sass'; | ||
import { pluginStylus } from '@rsbuild/plugin-stylus'; | ||
|
||
export default defineConfig({ | ||
plugins: [pluginLess(), pluginSass(), pluginStylus()], | ||
output: { | ||
filenameHash: false, | ||
}, | ||
}); |
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,4 @@ | ||
window.test1 = new URL('./test1.css', import.meta.url).href; | ||
window.test2 = new URL('./test2.less', import.meta.url).href; | ||
window.test3 = new URL('./test3.scss', import.meta.url).href; | ||
window.test4 = new URL('./test4.styl', import.meta.url).href; |
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; | ||
} |
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 @@ | ||
body { | ||
& .foo { | ||
color: blue; | ||
} | ||
} |
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 @@ | ||
body { | ||
& .foo { | ||
color: green; | ||
} | ||
} |
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 @@ | ||
body { | ||
& .foo { | ||
color: yellow; | ||
} | ||
} |
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
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
Oops, something went wrong.