提交 21f68018 编写于 作者: fxy060608's avatar fxy060608

chore(hbx): format log

上级 b8090531
......@@ -55,7 +55,6 @@ export const removeWarnFormatter: Formatter = {
}
const fileRE = /file:\s(.*):(\d+):(\d+)/
export const FilenameFormatter: Formatter = {
test(msg) {
return fileRE.test(msg)
......@@ -67,6 +66,18 @@ export const FilenameFormatter: Formatter = {
},
}
const vueFileRE = /file:\s(.*)\?vue&type=(.*)/
export const VueFilenameFormatter: Formatter = {
test(msg) {
return vueFileRE.test(msg)
},
format(msg) {
return msg.replace(vueFileRE, (_, filename) => {
return `file: ${filename.split('?')[0]}`
})
},
}
export const HBuilderXFileFormatter: Formatter = {
test(msg) {
return fileRE.test(msg)
......@@ -91,3 +102,23 @@ export const HBuilderXFileFormatter: Formatter = {
)
},
}
export const HBuilderXVueFileFormatter: Formatter = {
test(msg) {
return vueFileRE.test(msg)
},
format(msg) {
return (
msg
// remove color
.replace(/\x1B[[(?);]{0,2}(;?\d)*./g, '')
.replace(vueFileRE, (_, filename) => {
return (
'at ' +
normalizePath(path.relative(process.env.UNI_INPUT_DIR, filename)) +
':1'
)
})
)
},
}
......@@ -8,6 +8,8 @@ import {
removeWarnFormatter,
FilenameFormatter,
HBuilderXFileFormatter,
HBuilderXVueFileFormatter,
VueFilenameFormatter,
} from '../hbx/log'
export interface Formatter {
......@@ -25,8 +27,10 @@ const initErrFormattersOnce = once(() => {
}
if (runByHBuilderX()) {
errFormatters.push(HBuilderXFileFormatter)
errFormatters.push(HBuilderXVueFileFormatter)
} else {
errFormatters.push(FilenameFormatter)
errFormatters.push(VueFilenameFormatter)
}
})
......
......@@ -260,11 +260,11 @@ export function cssPostPlugin(
const processChunkCSS = async (
css: string,
{
dirname,
filename,
inlined,
minify,
}: {
dirname: string
filename: string
inlined: boolean
minify: boolean
}
......@@ -272,13 +272,17 @@ export function cssPostPlugin(
// replace asset url references with resolved url.
css = css.replace(assetUrlRE, (_, fileHash, postfix = '') => {
return normalizePath(
path.relative(dirname, getAssetFilename(fileHash, config) + postfix)
path.relative(
path.dirname(filename),
getAssetFilename(fileHash, config) + postfix
)
)
})
if (minify && config.build.minify) {
css = await minifyCSS(css, config)
}
return css
// 压缩后再处理,小程序平台会补充 @import nvue 代码,esbuild 的压缩会把 `@import "./nvue.css";` 的空格移除,变成 `@import"./nvue.css";` 在支付宝小程序中不支持
return chunkCssCode(filename, css)
}
const genCssCode = (fileName: string) => {
......@@ -288,8 +292,8 @@ export function cssPostPlugin(
}
for (const filename of cssChunks.keys()) {
const cssCode = genCssCode(filename)
let source = await processChunkCSS(chunkCssCode(filename, cssCode), {
dirname: path.dirname(filename),
let source = await processChunkCSS(cssCode, {
filename: filename,
inlined: false,
minify: true,
})
......
......@@ -54,7 +54,7 @@
"vite": "^2.6.14"
},
"uni-app": {
"compilerVersion": "3.2.10"
"compilerVersion": "3.2.14"
},
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册