mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(cli): move replaceCssImport fn
This commit is contained in:
parent
6074baa28d
commit
29a799cae6
@ -34,3 +34,12 @@ export function getCssBaseFile() {
|
|||||||
|
|
||||||
return null;
|
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')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,23 +1,13 @@
|
|||||||
// @ts-ignore
|
|
||||||
import { transformAsync } from '@babel/core';
|
import { transformAsync } from '@babel/core';
|
||||||
import { readFileSync, removeSync, outputFileSync } from 'fs-extra';
|
import { readFileSync, removeSync, outputFileSync } from 'fs-extra';
|
||||||
import { replaceExt } from '../common';
|
import { replaceExt } from '../common';
|
||||||
import { CSS_LANG } from '../common/css';
|
import { replaceCssImport } 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')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function compileJs(filePath: string): Promise<undefined> {
|
export function compileJs(filePath: string): Promise<undefined> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let code = readFileSync(filePath, 'utf-8');
|
let code = readFileSync(filePath, 'utf-8');
|
||||||
|
|
||||||
code = replaceStyleImport(code);
|
code = replaceCssImport(code);
|
||||||
|
|
||||||
transformAsync(code, { filename: filePath })
|
transformAsync(code, { filename: filePath })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user