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);
}