Skip to content

Commit a8b75ae

Browse files
committed
feat: scss compile support custom.scss
1 parent 581dd41 commit a8b75ae

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/semi-scss-compile/src/utils/generateSCSSMap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const generateComponentsScssMap = (foundationPath: string, iconPath?: string) =>
3838

3939

4040
const generateThemeScssMap = (themePath: string) => {
41-
const fileList = ['_font.scss', '_palette.scss', 'global.scss', 'animation.scss', 'index.scss', 'local.scss', 'mixin.scss', 'variables.scss'] as const;
41+
const fileList = ['_font.scss', '_palette.scss', 'global.scss', 'animation.scss', 'index.scss', 'local.scss', 'mixin.scss', 'variables.scss', 'custom.scss'] as const;
4242
const themeScssMap: { [key in typeof fileList[number]]?: string } = {};
4343
for (const fileName of fileList) {
4444
const scssAbsolutePath = path.join(themePath, 'scss', fileName);

packages/semi-scss-compile/src/utils/writeFile.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,28 @@ const preProcessScssMap = (scssMapOrigin: ReturnType<typeof generateScssMap>) =>
6565
}
6666
}
6767
}
68+
69+
//---- inject custom file custom.scss to component's variables.scss -----
70+
const customScssRaw = scssMap.theme['custom.scss'];
71+
let allCustomRaw = '';
72+
if (customScssRaw) {
73+
for (const componentName of Object.keys(scssMap['components'])) {
74+
if (scssMap['components'][componentName]['variables.scss']) {
75+
allCustomRaw+= scssMap['components'][componentName]['variables.scss']+'\n';
76+
}
77+
}
78+
allCustomRaw+= themeLocalRaw || "";
79+
allCustomRaw+="\n";
80+
allCustomRaw+=customScssRaw+"\n";
81+
scssMap.theme['index.scss'] += '\n'+allCustomRaw;
82+
}
83+
6884
//----- inject end -----
6985

7086
return {
7187
...{
7288
components: scssMap['components'],
73-
theme: lodash.omit(scssMap['theme'], 'local.scss')
89+
theme: lodash.omit(scssMap['theme'], 'local.scss', 'custom.scss')
7490
},
7591
index: compilerEntryContent
7692
};

0 commit comments

Comments
 (0)