kaola-fed / megalo-aot

MIT License
9 stars 5 forks source link

以vue文件作为入口时,自动生成的入口代码没有被 babel 编译 #58

Closed bigmeow closed 5 years ago

bigmeow commented 5 years ago

问题描述

当不写index.js时,megalo-target的vue-entry会自动生成并注入部分index.js的代码:

import Component from ${ JSON.stringify( '-!' + remainingRequest ) };
import Vue from 'vue';
Component.mpType = "${ entryKey === 'app' ? 'app' : 'page' }";
const app = new Vue(Component);
app.$mount()

代码地址:https://github.com/kaola-fed/megalo-aot/blob/03ef02b9d16f29f8822551e2a2e52c0894c5512e/packages/target/lib/frameworks/vue/loader/vue-entry.js

以aot中的demo为例,当编译后,打开dist目录下,找到生成后的js页面文件dist/package/static/js/package/pages/demo/index.js,在文件中搜索'const',可以看到下面的代码:

_Users_bigMeow_GitHub_megalo_megalo_aot_examples_vue_mp_node_modules_vue_loader_lib_index_js_vue_loader_options_Users_bigMeow_GitHub_megalo_megalo_aot_examples_vue_mp_src_package_pages_demo_index_vue__WEBPACK_IMPORTED_MODULE_0__["default"].mpType = "page";
const app = new vue__WEBPACK_IMPORTED_MODULE_1___default.a(_Users_bigMeow_GitHub_megalo_megalo_aot_examples_vue_mp_node_modules_vue_loader_lib_index_js_vue_loader_options_Users_bigMeow_GitHub_megalo_megalo_aot_examples_vue_mp_src_package_pages_demo_index_vue__WEBPACK_IMPORTED_MODULE_0__["default"]);
app.$mount();

这里有两个问题:

造成的影响

UglifyJsPlugin 压缩混淆时会报错

Unexpected token: keyword (const) 
bigmeow commented 5 years ago

暂时先这么解决了 https://github.com/kaola-fed/megalo-aot/pull/62/files

fengzilong commented 5 years ago

@megalo/target@0.6.2