优化scoped,
parent
cc027b3567
commit
a961c52c05
|
@ -21,7 +21,7 @@ function md5(str = '') {
|
||||||
return sum.digest('hex').slice(0, 8)
|
return sum.digest('hex').slice(0, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
function scopeCss(css, hash) {
|
function scopeCss(css = '', hash) {
|
||||||
let rules = css.matchAll(CSS_SHEET_EXP)
|
let rules = css.matchAll(CSS_SHEET_EXP)
|
||||||
|
|
||||||
return [...rules]
|
return [...rules]
|
||||||
|
|
|
@ -8,7 +8,7 @@ export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/
|
||||||
export const STYLE_EXP = /<style[^>]*?>([\w\W]*?)<\/style>/g
|
export const STYLE_EXP = /<style[^>]*?>([\w\W]*?)<\/style>/g
|
||||||
export const HTML_EXP = /<template[^>]*?>([\w\W]*?)<\/template>/
|
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 = {
|
export const COMMON_HEADERS = {
|
||||||
'Cache-Control': 'no-store'
|
'Cache-Control': 'no-store'
|
||||||
|
|
17
lib/prod.js
17
lib/prod.js
|
@ -1,6 +1,6 @@
|
||||||
import fs from 'iofs'
|
import fs from 'iofs'
|
||||||
import { join, resolve, dirname, parse } from 'path'
|
import { join, resolve, dirname, parse } from 'path'
|
||||||
|
import Es from 'esbuild'
|
||||||
import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js'
|
import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js'
|
||||||
|
|
||||||
const noc = Buffer.from('')
|
const noc = Buffer.from('')
|
||||||
|
@ -26,9 +26,12 @@ export default function compile(root = '', dist = '', conf = {}) {
|
||||||
currentPage = Object.keys(conf.pages)[0]
|
currentPage = Object.keys(conf.pages)[0]
|
||||||
page = conf.pages[currentPage]
|
page = conf.pages[currentPage]
|
||||||
|
|
||||||
console.log('正在生成 %s...', `${currentPage}.html`)
|
console.log('正在生成 %s ...', `${currentPage}.html`)
|
||||||
|
|
||||||
for (let it of list) {
|
for (let it of list) {
|
||||||
|
if (fs.isdir(it.path)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// 入口文件, 特殊处理
|
// 入口文件, 特殊处理
|
||||||
if (it.path === page.entry) {
|
if (it.path === page.entry) {
|
||||||
let entry = fs.cat(page.entry).toString()
|
let entry = fs.cat(page.entry).toString()
|
||||||
|
@ -40,7 +43,7 @@ export default function compile(root = '', dist = '', conf = {}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(' 解析 %s...', it.name)
|
console.log(' 解析 %s ...', it.name)
|
||||||
|
|
||||||
switch (it.ext) {
|
switch (it.ext) {
|
||||||
case '.vue':
|
case '.vue':
|
||||||
|
@ -52,7 +55,9 @@ export default function compile(root = '', dist = '', conf = {}) {
|
||||||
true
|
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
|
break
|
||||||
|
|
||||||
|
@ -61,7 +66,9 @@ export default function compile(root = '', dist = '', conf = {}) {
|
||||||
let code = fs.cat(it.path)
|
let code = fs.cat(it.path)
|
||||||
|
|
||||||
code = parseJs(code + '', conf.imports, { IS_MPA, currentPage }, true)
|
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
|
break
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
{
|
{
|
||||||
"name": "@bytedo/vue-live",
|
"name": "@bytedo/vue-live",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"bin": {
|
"bin": {
|
||||||
"vue-live": "index.js"
|
"vue-live": "index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"iofs": "^1.5.2",
|
"@bytedo/sass": "^1.54.8",
|
||||||
"@bytedo/sass": "^1.54.8"
|
"esbuild": "^0.15.13",
|
||||||
|
"iofs": "^1.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue