我在IE 11上遇到此错误:
这是我的webpack和babel配置:
webpack配置
const path = require('path');
const webpack = require('webpack');
const { VueLoaderPlugin } = require('vue-loader');
const StylishWebpackPlugin = require('webpack-stylish');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const withLogRocket = process.argv.includes('--with-logrocket');
if (withLogRocket) {
/* eslint-disable no-console */
console.info('-> Building with LogRocket enabled.');
/* eslint-enable */
}
// Base webpack configuration for all environments.
module.exports = {
context: path.dirname(__dirname),
entry: {
app: './src/main.js',
},
target: 'web',
output: {
filename: '[name].[contenthash].js',
hashDigestLength: 8,
},
resolve: {
extensions: ['.ts', '.js', '.vue'],
alias: {
'@': path.resolve(__dirname, '../src'),
},
},
module: {
rules: [
{
test: /\.js/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader',
],
},
],
},
stats: 'errors-only',
plugins: [
new VueLoaderPlugin(),
new ForkTsCheckerWebpackPlugin({
tslint: true,
reportFiles: ['src/**/*.ts'],
}),
new StylishWebpackPlugin(),
new webpack.DefinePlugin({
USE_LOGROCKET: withLogRocket,
}),
],
};
babelrc文件
{
"presets": ["env"],
"plugins": [
"transform-es2015-destructuring",
"transform-object-rest-spread"
]
}
我不确定这是...sources
的传播还是其他原因。我很确定我有babel-transform-object-rest-spread
软件包,但是我仍然不明白为什么会有这个错误,我也使用了babel-preset-env
。如您所见,我正在运行一个纯JS(VueJS,打字稿)应用程序。我已经阅读了许多有关使用polyfill的文章,但是这并没有帮助我使我们的应用程序在IE11上运行。
答案 0 :(得分:2)
您使用的是@hide
预设,但从未定义Babel应该为其生成代码的环境(因此,我认为在这种情况下不支持IE 11)。
没有任何配置选项,babel-preset-env的行为与babel-preset-latest(或babel-preset-es2015,babel-preset-es2016和babel-preset-es2017)完全相同。
因此,只需将具有env
属性设置的options对象添加到类似的对象中
targets
像这样:
"browsers": [ "last 1 version", "ie >= 11" ]
我也强烈建议您尽快切换到Babel 7。