feat(cli): add css.removeSourceFile config (#10750)

This commit is contained in:
neverland
2022-06-26 17:15:11 +08:00
committed by GitHub
parent e61d85a890
commit bb23e1b700
4 changed files with 48 additions and 4 deletions
@@ -1,11 +1,13 @@
import { parse } from 'path';
import { readFileSync, writeFileSync } from 'fs';
import { replaceExt } from '../common/index.js';
import fse from 'fs-extra';
import { getVantConfig, replaceExt } from '../common/index.js';
import { compileCss } from './compile-css.js';
import { compileLess } from './compile-less.js';
import { compileSass } from './compile-sass.js';
import { consola } from '../common/logger.js';
const { readFileSync, writeFileSync, removeSync } = fse;
async function compileFile(filePath: string) {
const parsedPath = parse(filePath);
@@ -30,6 +32,11 @@ async function compileFile(filePath: string) {
export async function compileStyle(filePath: string) {
const css = await compileFile(filePath);
const vantConfig = getVantConfig();
if (vantConfig.build?.css?.removeSourceFile) {
removeSync(filePath);
}
writeFileSync(replaceExt(filePath, '.css'), css);
}
@@ -12,6 +12,7 @@ import {
ES_DIR,
SRC_DIR,
LIB_DIR,
getVantConfig,
STYLE_DEPS_JSON_FILE,
} from '../common/constant.js';
@@ -87,8 +88,10 @@ export function genComponentStyle(
delete require.cache[STYLE_DEPS_JSON_FILE];
}
const vantConfig = getVantConfig();
const components = getComponents();
const baseFile = getCssBaseFile();
const hasSourceFile = vantConfig.build?.css?.removeSourceFile !== true;
components.forEach((component) => {
genEntry({
@@ -98,7 +101,7 @@ export function genComponentStyle(
ext: '.css',
});
if (CSS_LANG !== 'css') {
if (CSS_LANG !== 'css' && hasSourceFile) {
genEntry({
baseFile,
component,