Skip to content

Commit d80ec52

Browse files
committed
chore: rename RSLIB_CSS_ENTRY_FLAG
1 parent ba75641 commit d80ec52

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/core/src/config.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from './constant';
2020
import {
2121
type CssLoaderOptionsAuto,
22-
RSLIB_TEMP_CSS_DIR,
22+
RSLIB_CSS_ENTRY_FLAG,
2323
composeCssConfig,
2424
cssExternalHandler,
2525
isCssGlobalFile,
@@ -686,16 +686,28 @@ const composeEntryConfig = async (
686686
// Using the longest common path of all non-declaration input files by default.
687687
const outBase = lcp === null ? root : lcp;
688688

689-
for (const file of resolvedEntryFiles) {
689+
function getEntryName(file: string) {
690690
const { dir, name } = path.parse(path.relative(outBase, file));
691691
// Entry filename contains nested path to preserve source directory structure.
692692
const entryFileName = path.join(dir, name);
693693

694+
// 1. we mark the global css files (which will generate empty js chunk in cssExtract), and deleteAsset in RemoveCssExtractAssetPlugin
695+
// 2. avoid the same name e.g: `index.ts` and `index.css`
694696
if (isCssGlobalFile(file, cssModulesAuto)) {
695-
resolvedEntries[`${RSLIB_TEMP_CSS_DIR}/${entryFileName}`] = file;
696-
} else {
697-
resolvedEntries[entryFileName] = file;
697+
return `${RSLIB_CSS_ENTRY_FLAG}/${entryFileName}`;
698+
}
699+
700+
return entryFileName;
701+
}
702+
703+
for (const file of resolvedEntryFiles) {
704+
const entryName = getEntryName(file);
705+
if (resolvedEntries[entryName]) {
706+
logger.warn(
707+
`duplicate entry: ${entryName}, this may lead to the incorrect output, please rename the file`,
708+
);
698709
}
710+
resolvedEntries[entryName] = file;
699711
}
700712
}
701713

packages/core/src/css/cssConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CSS_EXTENSIONS_PATTERN } from '../constant';
99
import { RemoveCssExtractAssetPlugin } from './RemoveCssExtractAssetPlugin';
1010
const require = createRequire(import.meta.url);
1111

12-
export const RSLIB_TEMP_CSS_DIR = '__rslib_css__';
12+
export const RSLIB_CSS_ENTRY_FLAG = '__rslib_css__';
1313

1414
// https://rsbuild.dev/config/output/css-modules#cssmodulesauto
1515
export type CssLoaderOptionsAuto = CSSLoaderOptions['modules'] extends infer T
@@ -122,7 +122,7 @@ const pluginLibCss = (rootDir: string): RsbuildPlugin => ({
122122
.plugin(RemoveCssExtractAssetPlugin.name)
123123
.use(RemoveCssExtractAssetPlugin, [
124124
{
125-
include: new RegExp(`^${RSLIB_TEMP_CSS_DIR}`),
125+
include: new RegExp(`^${RSLIB_CSS_ENTRY_FLAG}`),
126126
},
127127
]);
128128

0 commit comments

Comments
 (0)