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