原文链接: vue cli3 打包兼容Android 4.4
已在Android4.4上跑通
未能兼容ios9, 会报一个type error, 但是又没有其他任何信息, 垃圾ios....
在vue.config.js中配置相关依赖进行转换
一般把第三方库加进去后就不会有es6的语法了, 包括const ,let , ... 等
1module.exports = { 2 transpileDependencies: [ 3 // can be string or regex 4 "@vue/", 5 "vue-router", 6 "core-js", 7 "core-js", 8 "proxy-polyfill", 9 // 尽量不要全部加进去, 会有很多问题 10 // /node_modules/ 11 ], 12};
babel.config.js
加入箭头函数和可选链的转义, 引入corejs3
1module.exports = { 2 presets: [ 3 [ 4 "@vue/cli-plugin-babel/preset", 5 { 6 useBuiltIns: "usage", 7 corejs: 3, // 指定版本 8 targets: { 9 ios: "8", 10 android: "4", 11 chrome: "58", 12 }, 13 }, 14 ], 15 ], 16 plugins: [ 17 "@babel/plugin-transform-arrow-functions", 18 "@babel/plugin-proposal-optional-chaining", 19 ], 20};
引入proxy和其他相关polyfill
1import "regenerator-runtime/runtime"; 2import "@babel/polyfill"; 3import ProxyPolyfillBuilder from "proxy-polyfill/src/proxy"; 4if (!window.Proxy) { 5 window.Proxy = ProxyPolyfillBuilder(); 6}