首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >webpack巴别塔前置IE 11

webpack巴别塔前置IE 11
EN

Stack Overflow用户
提问于 2019-03-19 22:33:18
回答 1查看 753关注 0票数 1

我使用了巴别塔的多层填充在webpack内部转译代码。我很惊讶IE 11显示这样的错误:IE 11 Object doesn't support property or method 'prepend'不是pollyfill应该添加这个函数吗?我知道有一些重复,我只是不知道如何配置webpack。我尝试了几种方法,但我不得不手动添加prepend函数,这样IE就会找到它。

与babel相关的包:

代码语言:javascript
复制
"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:

代码语言:javascript
复制
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中添加了如下函数

代码语言:javascript
复制
(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]);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-28 01:06:02

我发现巴别塔没有这些方法。我需要手动添加它们。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55243446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档