From dc1fea1bbb29ef3de67d48923db0a24b0367055c Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 26 Apr 2023 17:16:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=B9=E9=94=99=E5=A4=84?= =?UTF-8?q?=E7=90=86,=E9=81=BF=E5=85=8D=E4=BB=A3=E7=A0=81=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF=E6=97=B6=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E5=85=B7=E5=B4=A9=E6=BA=83=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compile-vue.js | 24 +++++++++++++++++++++--- package.json | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/compile-vue.js b/lib/compile-vue.js index 13f6269..3397212 100644 --- a/lib/compile-vue.js +++ b/lib/compile-vue.js @@ -10,6 +10,7 @@ import { createHash } from 'crypto' import Es from 'esbuild' import { join } from 'path' import { compile } from '@vue/compiler-dom' +import { red, cyan, blue } from 'kolorist' import { JS_EXP, @@ -103,7 +104,8 @@ export function parseJs( code = '', imports, { IS_MPA, currentPage, IS_ENTRY, DEPLOY_PATH } = {}, - isBuild + isBuild, + filename ) { let fixedStyle = '\n\n' let ASSETS_DIR = '/@/' @@ -111,7 +113,23 @@ export function parseJs( if (isBuild) { ASSETS_DIR = '/assets/' // + (IS_MPA ? 'pages/' : '') } - code = Es.transformSync(code).code || '' + try { + code = Es.transformSync(code).code || '' + } catch (e) { + let err = e.errors.pop() + console.log('%s: %s', red('Uncaught SyntaxError'), err.text) + console.log( + ' @ line %d: %s', + err.location.line, + cyan(err.location.lineText) + ) + console.log( + ' @ %s:%d:%d', + blue(filename), + err.location.line, + err.location.column + ) + } return ( code @@ -275,7 +293,7 @@ export function compileVue(file, imports, options = {}, isBuild) { CACHE[file] = { changed: false, js, html } } - output += parseJs(js, imports, options, isBuild).replace( + output += parseJs(js, imports, options, isBuild, file).replace( 'export default {', 'const __sfc__ = {\n render,\n' ) diff --git a/package.json b/package.json index 44221f6..174a6ca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fite", "type": "module", - "version": "0.7.1", + "version": "0.7.2", "bin": { "fite": "index.js" },