Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: localIdentName hashDigest has been supported in rspack mode #2331

Merged
merged 4 commits into from
May 14, 2024
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
42 changes: 42 additions & 0 deletions e2e/cases/css/css-modules/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,45 @@ test('should compile CSS Modules follow by output.cssModules', async () => {
/.the-a-class{color:red}.the-b-class-\w{6}{color:blue}.the-c-class{color:yellow}.the-d-class{color:green}/,
);
});

test('should compile CSS Modules follow by output.cssModules custom localIdentName', async () => {
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
output: {
cssModules: {
localIdentName: '[hash:base64:8]',
},
},
},
});
const files = await rsbuild.unwrapOutputJSON();

const content =
files[Object.keys(files).find((file) => file.endsWith('.css'))!];

expect(content).toMatch(
/\.the-a-class{color:red}\.\w{8}{color:blue}\.\w{8}{color:yellow}\.the-d-class{color:green}/,
);
});

test('should compile CSS Modules follow by output.cssModules custom localIdentName - hashDigest', async () => {
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
output: {
cssModules: {
localIdentName: '[hash:hex:4]',
},
},
},
});
const files = await rsbuild.unwrapOutputJSON();

const content =
files[Object.keys(files).find((file) => file.endsWith('.css'))!];

expect(content).toMatch(
/\.the-a-class{color:red}\.\w{4}{color:blue}\.\w{4}{color:yellow}\.the-d-class{color:green}/,
);
});
19 changes: 0 additions & 19 deletions packages/core/tests/css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,6 @@ describe('plugin-css', () => {
);
});

it('should ignore hashDigest when custom cssModules.localIdentName', async () => {
const rsbuild = await createStubRsbuild({
plugins: [pluginCss()],
rsbuildConfig: {
output: {
cssModules: {
localIdentName: '[hash:base64:5]',
},
},
},
});

const bundlerConfigs = await rsbuild.initConfigs();

expect(JSON.stringify(bundlerConfigs[0])).toContain(
'"localIdentName":"[hash:base64:5]"',
);
});

it('should use custom cssModules rule when using output.cssModules config', async () => {
const rsbuild = await createStubRsbuild({
plugins: [pluginCss()],
Expand Down
4 changes: 0 additions & 4 deletions website/docs/en/config/output/css-modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ You can use the following template strings in `localIdentName`:
- `[ext]` - extension with leading dot.
- `[hash:<hashDigest>:<hashDigestLength>]`: hash with hash settings.

:::tip
When using Rspack as the bundler, currently does not support custom `<hashDigest>`.
:::

### Example

Set `localIdentName` to other value:
Expand Down
4 changes: 0 additions & 4 deletions website/docs/zh/config/output/css-modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ console.log(styles.header);
- `[ext]` - 文件后缀名,包含点号。
- `[hash:<hashDigest>:<hashDigestLength>]` - 带有哈希设置的哈希。

:::tip
在使用 Rspack 作为打包工具时, 暂不支持配置 `<hashDigest>`。
:::

### 示例

将 `localIdentName` 设置为其他值:
Expand Down
Loading