chore(cli): move replaceCssImport fn

This commit is contained in:
陈嘉涵 2020-01-10 14:20:57 +08:00
parent 6074baa28d
commit 29a799cae6
2 changed files with 11 additions and 12 deletions

View File

@ -34,3 +34,12 @@ export function getCssBaseFile() {
return null;
}
const IMPORT_STYLE_RE = /import\s+?(?:(?:".*?")|(?:'.*?'))[\s]*?(?:;|$|)/g;
// "import 'a.less';" => "import 'a.css';"
export function replaceCssImport(code: string) {
return code.replace(IMPORT_STYLE_RE, str =>
str.replace(`.${CSS_LANG}`, '.css')
);
}

View File

@ -1,23 +1,13 @@
// @ts-ignore
import { transformAsync } from '@babel/core';
import { readFileSync, removeSync, outputFileSync } from 'fs-extra';
import { replaceExt } from '../common';
import { CSS_LANG } from '../common/css';
const IMPORT_STYLE_RE = /import\s+?(?:(?:".*?")|(?:'.*?'))[\s]*?(?:;|$|)/g;
// "import 'a.less';" => "import 'a.css';"
function replaceStyleImport(code: string) {
return code.replace(IMPORT_STYLE_RE, str =>
str.replace(`.${CSS_LANG}`, '.css')
);
}
import { replaceCssImport } from '../common/css';
export function compileJs(filePath: string): Promise<undefined> {
return new Promise((resolve, reject) => {
let code = readFileSync(filePath, 'utf-8');
code = replaceStyleImport(code);
code = replaceCssImport(code);
transformAsync(code, { filename: filePath })
.then(result => {