优化scoped,

pull/1/head
yutent 2022-11-03 18:22:42 +08:00
parent cc027b3567
commit a961c52c05
4 changed files with 18 additions and 10 deletions

View File

@ -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]

View File

@ -8,7 +8,7 @@ export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/
export const STYLE_EXP = /<style[^>]*?>([\w\W]*?)<\/style>/g
export const HTML_EXP = /<template[^>]*?>([\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'

View File

@ -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('')
@ -29,6 +29,9 @@ export default function compile(root = '', dist = '', conf = {}) {
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()
@ -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

View File

@ -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"
}
}