无法为 IE 11 编译 Vue.js
Cannot compile Vue.js for IE 11
所以我最近问了一个关于这个 here 的问题,经过大量谷歌搜索和尝试,这就是我的 babel.rc
:
{
"presets": [["env", {
"modules": false,
"uglify": true,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"vue",
"vue-app",
"stage-2"
],
"plugins": ["transform-runtime", "transform-vue-jsx"]
}
这就是我的 webpack:
let mix = require('laravel-mix');
var path = require('path');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
var npm = '/node_modules/';
var paths = {
'jquery-ui': npm + 'jquery-ui/',
'bootstrap': npm + 'bootstrap/',
'select2': npm + 'select2/dist/',
'lightbox2': npm + 'lightbox2/dist/',
'accounting': npm + 'accounting/',
'polly-fill': npm + '@babel/polyfill/dist/',
};
var jQueryUITheme = 'ui-lightness';
mix.less('resources/assets/less/style.less', 'public/css/', {
modifyVars: {
'bootstrap': '"' + path.resolve(__dirname) + paths['bootstrap'] + 'less/' + '"'
}
}).js('resources/assets/js/boot.js', 'public/js/all.js').webpackConfig({
resolve: {
alias: {
"matches-selector/matches-selector": "desandro-matches-selector",
"eventEmitter/EventEmitter": "wolfy87-eventemitter",
"get-style-property/get-style-property": "desandro-get-style-property",
'masonry': 'masonry-layout',
'isotope': 'isotope-layout',
'isotope/js/layout-mode': 'isotope-layout/js/layoutmode',
'pace': 'pace-progress',
"jquery-ui/ui/widget": "jquery-ui/widget.js",
}
},
}).js('resources/assets/js/vue/main.js', 'public/js/vue.js')
.scripts([
'resources/assets/js/lib/jquery.validate.min.js',
'resources/assets/js/lib/jquery.bootstrap.wizard.min.js',
path.resolve(__dirname) + paths['accounting'] + 'accounting.js'
], 'public/js/genesis.js')
.copy(path.resolve(__dirname) + paths['jquery-ui'] + 'themes/' + jQueryUITheme + '/jquery-ui.min.css', 'public/css/lib/jquery-ui/jquery-ui.min.css')
.copy(path.resolve(__dirname) + paths['jquery-ui'] + 'themes/' + jQueryUITheme + '/theme.css', 'public/css/lib/jquery-ui/theme.css')
.copy(path.resolve(__dirname) + paths['jquery-ui'] + 'themes/' + jQueryUITheme + '/images', 'public/css/lib/jquery-ui/images')
.copy(path.resolve(__dirname) + paths['select2'] + 'css/select2.min.css', 'public/css/lib/select2/select2.min.css')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'css/lightbox.min.css', 'public/css/lib/lightbox2/css')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/loading.gif', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/close.png', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/next.png', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/prev.png', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['polly-fill'] + 'polyfill.min.js', 'public/js/')
.copy(path.resolve(__dirname) + '/resources/assets/js/lib/pace.js', 'public/js/')
.sourceMaps();
mix.babel(['public/js/main.js'], 'public/js/main.js');
mix.babel(['public/js/vue.js'], 'public/js/vue.js');
mix.minify(['public/js/main.js', 'public/js/vue.js', 'public/css/style.css']);
我 了解 ie 11 不以任何方式支持任何高于 es5 的东西 我的 vue JS 仍然没有编译到 ES5,我最后一个问题的输出仍然是相同。我对如何将 Vue JS 编译为 ES5 感到困惑,以至于我没有得到以下信息:
错误:
SCRIPT1002: Syntax error
vue.js (16,8498)
好的,这一行是什么?
(module,__webpack_exports__,__webpack_require__){"use strict";eval("/* unused harmony export getJSON */\n/* unused harmony export getScrollBarWidth */\n/* unused harmony export translations */\n/* harmony export (immutable) */ __webpack_exports__[\"b\"] = delayer;\n/* unused harmony export VueFixer */\n// coerce convert som types of data into another type\nconst coerce = {\n // Convert a string to booleam. Otherwise, return the value without modification, so if is not boolean, Vue throw a warning.\n boolean: val => (typeof val === 'string' ? val === '' || val === 'true' ? true : (val === 'false' || val === 'null' || val === 'undefined' ? false : val) : val),\n // Attempt to convert a string value to a Number. Otherwise, return 0.\n number: (val, alt = null) => (typeof val === 'number' ? val : val === undefined || val === null || isNaN(Number(val)) ? alt :
我不确定我使用的是什么版本的 webpack,因为我正在使用 Laravel Mix,但我使用的是 babel 6.
一切都可以正常编译,但 Vue JS 仍然无法正确编译为适用于 IE 11 的 ES5。
number: (val, alt = null) => (typeof val === 'number' ? val : val === undefined.....
在你的包代码中对我说箭头函数没有被转换成普通函数。尝试添加 transform-es2015-arrow-functions
babel 插件。如果您仍然会遇到类似的错误 - 尝试分析您的包的代码并找到哪些 ES6 feature not supported by IE11 保留在那里。
所以我最近问了一个关于这个 here 的问题,经过大量谷歌搜索和尝试,这就是我的 babel.rc
:
{
"presets": [["env", {
"modules": false,
"uglify": true,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"vue",
"vue-app",
"stage-2"
],
"plugins": ["transform-runtime", "transform-vue-jsx"]
}
这就是我的 webpack:
let mix = require('laravel-mix');
var path = require('path');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
var npm = '/node_modules/';
var paths = {
'jquery-ui': npm + 'jquery-ui/',
'bootstrap': npm + 'bootstrap/',
'select2': npm + 'select2/dist/',
'lightbox2': npm + 'lightbox2/dist/',
'accounting': npm + 'accounting/',
'polly-fill': npm + '@babel/polyfill/dist/',
};
var jQueryUITheme = 'ui-lightness';
mix.less('resources/assets/less/style.less', 'public/css/', {
modifyVars: {
'bootstrap': '"' + path.resolve(__dirname) + paths['bootstrap'] + 'less/' + '"'
}
}).js('resources/assets/js/boot.js', 'public/js/all.js').webpackConfig({
resolve: {
alias: {
"matches-selector/matches-selector": "desandro-matches-selector",
"eventEmitter/EventEmitter": "wolfy87-eventemitter",
"get-style-property/get-style-property": "desandro-get-style-property",
'masonry': 'masonry-layout',
'isotope': 'isotope-layout',
'isotope/js/layout-mode': 'isotope-layout/js/layoutmode',
'pace': 'pace-progress',
"jquery-ui/ui/widget": "jquery-ui/widget.js",
}
},
}).js('resources/assets/js/vue/main.js', 'public/js/vue.js')
.scripts([
'resources/assets/js/lib/jquery.validate.min.js',
'resources/assets/js/lib/jquery.bootstrap.wizard.min.js',
path.resolve(__dirname) + paths['accounting'] + 'accounting.js'
], 'public/js/genesis.js')
.copy(path.resolve(__dirname) + paths['jquery-ui'] + 'themes/' + jQueryUITheme + '/jquery-ui.min.css', 'public/css/lib/jquery-ui/jquery-ui.min.css')
.copy(path.resolve(__dirname) + paths['jquery-ui'] + 'themes/' + jQueryUITheme + '/theme.css', 'public/css/lib/jquery-ui/theme.css')
.copy(path.resolve(__dirname) + paths['jquery-ui'] + 'themes/' + jQueryUITheme + '/images', 'public/css/lib/jquery-ui/images')
.copy(path.resolve(__dirname) + paths['select2'] + 'css/select2.min.css', 'public/css/lib/select2/select2.min.css')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'css/lightbox.min.css', 'public/css/lib/lightbox2/css')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/loading.gif', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/close.png', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/next.png', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['lightbox2'] + 'images/prev.png', 'public/css/lib/lightbox2/images')
.copy(path.resolve(__dirname) + paths['polly-fill'] + 'polyfill.min.js', 'public/js/')
.copy(path.resolve(__dirname) + '/resources/assets/js/lib/pace.js', 'public/js/')
.sourceMaps();
mix.babel(['public/js/main.js'], 'public/js/main.js');
mix.babel(['public/js/vue.js'], 'public/js/vue.js');
mix.minify(['public/js/main.js', 'public/js/vue.js', 'public/css/style.css']);
我 了解 ie 11 不以任何方式支持任何高于 es5 的东西 我的 vue JS 仍然没有编译到 ES5,我最后一个问题的输出仍然是相同。我对如何将 Vue JS 编译为 ES5 感到困惑,以至于我没有得到以下信息:
错误:
SCRIPT1002: Syntax error
vue.js (16,8498)
好的,这一行是什么?
(module,__webpack_exports__,__webpack_require__){"use strict";eval("/* unused harmony export getJSON */\n/* unused harmony export getScrollBarWidth */\n/* unused harmony export translations */\n/* harmony export (immutable) */ __webpack_exports__[\"b\"] = delayer;\n/* unused harmony export VueFixer */\n// coerce convert som types of data into another type\nconst coerce = {\n // Convert a string to booleam. Otherwise, return the value without modification, so if is not boolean, Vue throw a warning.\n boolean: val => (typeof val === 'string' ? val === '' || val === 'true' ? true : (val === 'false' || val === 'null' || val === 'undefined' ? false : val) : val),\n // Attempt to convert a string value to a Number. Otherwise, return 0.\n number: (val, alt = null) => (typeof val === 'number' ? val : val === undefined || val === null || isNaN(Number(val)) ? alt :
我不确定我使用的是什么版本的 webpack,因为我正在使用 Laravel Mix,但我使用的是 babel 6.
一切都可以正常编译,但 Vue JS 仍然无法正确编译为适用于 IE 11 的 ES5。
number: (val, alt = null) => (typeof val === 'number' ? val : val === undefined.....
在你的包代码中对我说箭头函数没有被转换成普通函数。尝试添加 transform-es2015-arrow-functions
babel 插件。如果您仍然会遇到类似的错误 - 尝试分析您的包的代码并找到哪些 ES6 feature not supported by IE11 保留在那里。