1
0
mirror of https://github.com/WeBankFinTech/fes.js.git synced 2025-04-06 03:59:53 +08:00
qlin 3c1290fc58
feat: 增加配置控制全局样式加载顺序 ()
* docs: remove pwa

* fix: 全局样式覆盖问题

* fix: 修复全局样式加载顺序问题

* chore: 优化代码
2023-06-02 10:59:31 +08:00

42 lines
1.2 KiB
JavaScript

import { relative, join } from 'path';
import { existsSync } from 'fs';
export default (api) => {
api.describe({
key: 'globalCSS',
config: {
schema(joi) {
return joi.string();
},
},
default: '',
});
const { paths, utils } = api;
const { absSrcPath = '', absTmpPath = '' } = paths;
const files = ['global.css', 'global.less', 'global.scss', 'global.sass', 'global.styl', 'global.stylus'];
const globalCSSFile = files
.map((file) => join(absSrcPath || '', file))
.filter((file) => existsSync(file))
.slice(0, 1);
const isBeforeImports = () => api.config.globalCSS === 'beforeImports';
if (globalCSSFile.length) {
api.addEntryImportsAhead({
stage: 1,
fn: () => {
if (isBeforeImports()) {
return [{ source: relative(absTmpPath, globalCSSFile[0]) }];
}
return [];
},
});
api.addEntryCodeAhead(() => {
if (!isBeforeImports()) {
return `import '${utils.winPath(relative(absTmpPath, globalCSSFile[0]))}';`;
}
return [];
});
}
};