-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new
output.emitCss
config (#3967)
- Loading branch information
1 parent
425b3fc
commit 917318d
Showing
14 changed files
with
195 additions
and
96 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,105 @@ | ||
import { build } from '@e2e/helper'; | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('should not emit CSS files when build node target', async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
output: { | ||
target: 'node', | ||
}, | ||
}, | ||
}); | ||
const files = await rsbuild.unwrapOutputJSON(); | ||
|
||
// preserve CSS Modules mapping | ||
const jsContent = | ||
files[Object.keys(files).find((file) => file.endsWith('.js'))!]; | ||
expect(jsContent.includes('"title-class":')).toBeTruthy(); | ||
|
||
const cssFiles = Object.keys(files).filter((file) => file.endsWith('.css')); | ||
expect(cssFiles).toHaveLength(0); | ||
}); | ||
|
||
test('should allow to emit CSS with output.emitCss when build node target', async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
output: { | ||
target: 'node', | ||
emitCss: true, | ||
}, | ||
}, | ||
}); | ||
const files = await rsbuild.unwrapOutputJSON(); | ||
|
||
// preserve CSS Modules mapping | ||
const jsContent = | ||
files[Object.keys(files).find((file) => file.endsWith('.js'))!]; | ||
expect(jsContent.includes('"title-class":')).toBeTruthy(); | ||
|
||
const cssFiles = Object.keys(files).filter((file) => file.endsWith('.css')); | ||
expect(cssFiles).toHaveLength(1); | ||
}); | ||
|
||
test('should not emit CSS files when build web-worker target', async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
output: { | ||
target: 'web-worker', | ||
}, | ||
}, | ||
}); | ||
const files = await rsbuild.unwrapOutputJSON(); | ||
|
||
// preserve CSS Modules mapping | ||
const jsContent = | ||
files[Object.keys(files).find((file) => file.endsWith('.js'))!]; | ||
expect(jsContent.includes('"title-class":')).toBeTruthy(); | ||
|
||
const cssFiles = Object.keys(files).filter((file) => file.endsWith('.css')); | ||
expect(cssFiles).toHaveLength(0); | ||
}); | ||
|
||
test('should allow to emit CSS with output.emitCss when build web-worker target', async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
output: { | ||
target: 'web-worker', | ||
emitCss: true, | ||
}, | ||
}, | ||
}); | ||
const files = await rsbuild.unwrapOutputJSON(); | ||
|
||
// preserve CSS Modules mapping | ||
const jsContent = | ||
files[Object.keys(files).find((file) => file.endsWith('.js'))!]; | ||
expect(jsContent.includes('"title-class":')).toBeTruthy(); | ||
|
||
const cssFiles = Object.keys(files).filter((file) => file.endsWith('.css')); | ||
expect(cssFiles).toHaveLength(1); | ||
}); | ||
|
||
test('should allow to disable CSS emit with output.emitCss when build web target', async () => { | ||
const rsbuild = await build({ | ||
cwd: __dirname, | ||
rsbuildConfig: { | ||
output: { | ||
target: 'web', | ||
emitCss: false, | ||
}, | ||
}, | ||
}); | ||
const files = await rsbuild.unwrapOutputJSON(); | ||
|
||
// preserve CSS Modules mapping | ||
const jsContent = | ||
files[Object.keys(files).find((file) => file.endsWith('.js'))!]; | ||
expect(jsContent.includes('"title-class":')).toBeTruthy(); | ||
|
||
const cssFiles = Object.keys(files).filter((file) => file.endsWith('.css')); | ||
expect(cssFiles).toHaveLength(0); | ||
}); |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
e2e/cases/css/ignore-css/src/index.js → e2e/cases/css/emit-css/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import './a.css'; | ||
import style from './b.module.scss'; | ||
import style from './b.module.css'; | ||
|
||
console.log(style); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,27 @@ | ||
# output.emitCss | ||
|
||
- **Type:** `boolean` | ||
- **Default:** `true` when [output.target](/config/output/target) is `web`, otherwise `false` | ||
|
||
Whether to emit CSS to the output bundles. | ||
|
||
If `false`, the CSS will not be extracted to separate files or injected into the JavaScript bundles via [output.injectStyles](/config/output/inject-styles). | ||
|
||
:::tip | ||
|
||
When `output.emitCss` is `false`, the class name information of CSS Modules will still be injected into the JS bundles, which helps to ensure the correctness of CSS Modules class names in SSR. | ||
|
||
::: | ||
|
||
## Example | ||
|
||
When building Node.js bundles, if you need to output CSS files, you can set `output.emitCss` to `true`: | ||
|
||
```js | ||
export default { | ||
output: { | ||
target: 'node', | ||
emitCss: true, | ||
}, | ||
}; | ||
``` |
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.