diff --git a/lib/compile-vue.js b/lib/compile-vue.js index 106a672..13f1167 100644 --- a/lib/compile-vue.js +++ b/lib/compile-vue.js @@ -21,7 +21,7 @@ function md5(str = '') { return sum.digest('hex').slice(0, 8) } -function scopeCss(css, hash) { +function scopeCss(css = '', hash) { let rules = css.matchAll(CSS_SHEET_EXP) return [...rules] diff --git a/lib/constants.js b/lib/constants.js index b56dae9..d77fafe 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -8,7 +8,7 @@ export const JS_EXP = /]*?>([\w\W]*?)<\/script>/ export const STYLE_EXP = /]*?>([\w\W]*?)<\/style>/g export const HTML_EXP = /]*?>([\w\W]*?)<\/template>/ -export const CSS_SHEET_EXP = /([\w\.,#\-:\(\)\[\]"'\=\s]+)\{([^\{\}]*?)\}/g +export const CSS_SHEET_EXP = /([\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{([^\{\}]*?)\}/g export const COMMON_HEADERS = { 'Cache-Control': 'no-store' diff --git a/lib/prod.js b/lib/prod.js index 0360f96..ae425d0 100644 --- a/lib/prod.js +++ b/lib/prod.js @@ -1,6 +1,6 @@ import fs from 'iofs' import { join, resolve, dirname, parse } from 'path' - +import Es from 'esbuild' import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js' const noc = Buffer.from('') @@ -26,9 +26,12 @@ export default function compile(root = '', dist = '', conf = {}) { currentPage = Object.keys(conf.pages)[0] page = conf.pages[currentPage] - console.log('正在生成 %s...', `${currentPage}.html`) + console.log('正在生成 %s ...', `${currentPage}.html`) for (let it of list) { + if (fs.isdir(it.path)) { + continue + } // 入口文件, 特殊处理 if (it.path === page.entry) { let entry = fs.cat(page.entry).toString() @@ -40,7 +43,7 @@ export default function compile(root = '', dist = '', conf = {}) { continue } - console.log(' 解析 %s...', it.name) + console.log(' 解析 %s ...', it.name) switch (it.ext) { case '.vue': @@ -52,7 +55,9 @@ export default function compile(root = '', dist = '', conf = {}) { true ) - fs.echo(code, join(dist, `assets/js/${it.name.split('.').shift()}.js`)) + Es.transform(code, { minify: true }).then(r => { + fs.echo(r.code, join(dist, `assets/js/${it.name.split('.').shift()}.js`)) + }) } break @@ -61,7 +66,9 @@ export default function compile(root = '', dist = '', conf = {}) { let code = fs.cat(it.path) code = parseJs(code + '', conf.imports, { IS_MPA, currentPage }, true) - fs.echo(code, join(dist, `assets/js/${it.name}`)) + Es.transform(code, { minify: true }).then(r => { + fs.echo(r.code, join(dist, `assets/js/${it.name}`)) + }) } break diff --git a/package.json b/package.json index fc1cb5b..8483369 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "@bytedo/vue-live", "type": "module", - "version": "0.0.12", + "version": "0.0.13", "bin": { "vue-live": "index.js" }, "dependencies": { - "iofs": "^1.5.2", - "@bytedo/sass": "^1.54.8" + "@bytedo/sass": "^1.54.8", + "esbuild": "^0.15.13", + "iofs": "^1.5.2" } }