From 661542fa415b73cf2a1e1a0bf7982f4417df83d5 Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 20 Apr 2023 13:53:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.js | 9 ++++----- lib/utils.js | 14 +++++--------- package.json | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index ed97c7d..c959ea0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -53,16 +53,15 @@ export default function compile(root = '', isProd = false, es) { let code = fs.cat(filePath).toString() console.log('编译 %s ...', blue(file)) try { + code = code.replace(/css`([\w\W]*?)`/g, function (m, scss) { + scss = compileScss(scss) + return `css\`${scss}\`` + }) code = Es.transformSync(code, OPTIONS).code } catch (err) { console.log('compile scss: ', file) console.error(err) } - - code = code.replace(/css`([\w\W]*?)`/g, function (m, scss) { - scss = compileScss(scss) - return `css\`${scss}\`` - }) fs.echo(code, target) } break diff --git a/lib/utils.js b/lib/utils.js index 6fe1590..c02bb60 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -8,19 +8,15 @@ const OPTIONS = { /** * 编译scss为css - * @param file 文件路径或scss代码 + * @param source scss代码 * @param mini 是否压缩 */ -export function compileScss(file, mini = true) { +export function compileScss(source, mini = true) { let style = mini ? 'compressed' : 'expanded' try { - if (fs.isfile(file)) { - return scss.compile(file, { style, ...OPTIONS }).css.trim() - } else { - return scss - .compileString(file.replace(/@loop/g, '@each'), { style, ...OPTIONS }) - .css.trim() - } + return scss + .compileString(source.replace(/@loop/g, '@each'), { style, ...OPTIONS }) + .css.trim() } catch (err) { console.log('compile scss: ', file) console.error(err) diff --git a/package.json b/package.json index a8ae1a8..4fce0b6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@bd/wcui-cli", "type": "module", - "version": "1.2.0", + "version": "1.2.1", "bin": { "wcui-cli": "index.js" },