Skip to content

Commit 63d4038

Browse files
committed
chore: adopt suggestions
1 parent cbeff88 commit 63d4038

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

packages/core/src/css/LibCssExtractLoader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* The following code is modified based on
33
* https://github.com/web-infra-dev/rspack/blob/0a89e433a9f8596a7c6c4326542f168b5982d2da/packages/rspack/src/builtin-plugin/css-extract/loader.ts
4+
* 1. remove hmr/webpack runtime
5+
* 2. add `this.emitFile` to emit css files
6+
* 3. add `import './[name].css';`
47
*/
58
import path, { extname } from 'node:path';
69
import type { LoaderDefinition } from '@rspack/core';

packages/core/src/css/cssConfig.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
import { createRequire } from 'node:module';
12
import path from 'node:path';
2-
import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
3+
import type {
4+
CSSLoaderOptions,
5+
RsbuildConfig,
6+
RsbuildPlugin,
7+
} from '@rsbuild/core';
38
import { CSS_EXTENSIONS_PATTERN } from '../constant';
49
import { RemoveCssExtractAssetPlugin } from './RemoveCssExtractAssetPlugin';
10+
const require = createRequire(import.meta.url);
511

612
export const RSLIB_TEMP_CSS_DIR = '__rslib_css__';
713

8-
// https://rsbuild.dev/zh/config/output/css-modules#cssmodulesauto
9-
export type CssLoaderOptionsAuto =
10-
| boolean
11-
| RegExp
12-
| ((
13-
resourcePath: string,
14-
resourceQuery: string,
15-
resourceFragment: string,
16-
) => boolean);
14+
// https://rsbuild.dev/config/output/css-modules#cssmodulesauto
15+
export type CssLoaderOptionsAuto = CSSLoaderOptions['modules'] extends infer T
16+
? T extends { auto?: any }
17+
? T['auto']
18+
: never
19+
: never;
1720

1821
export function isCssFile(filepath: string): boolean {
1922
return CSS_EXTENSIONS_PATTERN.test(filepath);

tests/integration/style/less/bundle-false/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "less-bundle-test",
2+
"name": "less-bundle-false-test",
33
"version": "1.0.0",
44
"private": true,
55
"type": "module"

tests/integration/style/less/bundle-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "less-bundle-test",
2+
"name": "less-bundle-import-test",
33
"version": "1.0.0",
44
"private": true,
55
"type": "module"

0 commit comments

Comments
 (0)