我使用了巴别塔的多层填充在webpack内部转译代码。我很惊讶IE 11显示这样的错误:IE 11 Object doesn't support property or method 'prepend'不是pollyfill应该添加这个函数吗?我知道有一些重复,我只是不知道如何配置webpack。我尝试了几种方法,但我不得不手动添加prepend函数,这样IE就会找到它。
与babel相关的包:
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"ajv": "^6.7.0",
"autoprefixer": "^9.4.6",
"babel-loader": "^8.0.5",
"breakpoint-sass": "^2.7.1",
"browserslist": "^4.4.1",
"clean-webpack-plugin": "^1.0.1",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^2.1.0"
}webpack.config.js:
module.exports = ( env, options ) => {
return {
entry : ['@babel/polyfill', './source/_assets/app.js'],
output : {
path : path.resolve( __dirname, 'public/dist' ),
filename : 'bundle.js',
chunkFilename : '[name].bundle.js',
publicPath : ( options.mode === 'production' ) ? '/themes/custom/avonis/public/dist/' : '../../dist/'
}, ...
{
test : /\.js$/,
exclude : /node_modules/,
use : {
loader : 'babel-loader',
options : {
presets : [ '@babel/preset-env' ],
plugins : [ '@babel/plugin-syntax-dynamic-import' ]
}
}
},我在入口文件app.js中添加了如下函数
(function (arr) {
arr.forEach(function (item) {
if (item.hasOwnProperty('append')) {
return;
}
Object.defineProperty(item, 'append', {
configurable: true,
enumerable: true,
writable: true,
value: function append() {
var argArr = Array.prototype.slice.call(arguments),
docFrag = document.createDocumentFragment();
argArr.forEach(function (argItem) {
var isNode = argItem instanceof Node;
docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
});
this.appendChild(docFrag);
}
});
});
})([Element.prototype, Document.prototype DocumentFragment.prototype]);发布于 2019-03-28 01:06:02
我发现巴别塔没有这些方法。我需要手动添加它们。
https://stackoverflow.com/questions/55243446
复制相似问题