首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Weback清单文件不编译为es5

Weback清单文件不编译为es5
EN

Stack Overflow用户
提问于 2018-11-05 18:34:58
回答 1查看 65关注 0票数 1

最近,由于webpack清单文件中包含.includes,而IE11无法运行,我们的构建已经停止了对IE11的工作。

我对此进行了深入研究,发现react-datepicker在它的代码中使用了.includes(),但是在我们的main.app.js文件中,它会转换它,所以这里没有任何东西,只有在清单文件中。

如果我从webpack中删除清单文件,错误将转移到main.app.js文件中,该文件名为object doesn't support property or method includes。此错误来自来自camelCase.js的redux-actions。我觉得这是红鲱鱼,但不完全确定。

我不知道这是webpack的问题,还是巴贝尔的问题,还是插件的错误。

我该怎么解决这个问题?

到目前为止我已经完成的步骤,

我在我们的package.json中锁定了16.3.0版本的响应。

我降低了react-datepicker插件的级别。

我已经从加载中删除了清单文件。

我已经尝试过更新redux-actions

我试过降低redux-actions的评级

这是webpack的档案:

代码语言:javascript
复制
const pkg = require('../package.json');
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const appConfig = {
  VERSION: pkg.version,
  OUTPUT_NAME: pkg.config.OUTPUT_NAME,
  DEV_PORT: pkg.config.DEV_PORT
};

const config = {
  mode: 'development',
  context: path.resolve(__dirname),
  entry: {
    app: [
      '../src/index.js',
      '../src/styles/main.css',
      '../index.pug'
    ]
  },
  output: {
    path: path.resolve(__dirname, '../public/'),
    filename: `scripts/${appConfig.OUTPUT_NAME}.[name].${appConfig.VERSION}.js`,
    publicPath: '/'
  },
  resolve: {
    extensions: [ '.js', '.jsx' ]
  },
  externals: {
    'lottie-web': 'lottie'
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      },
      {
        test: /\.(css|scss)$/,
        exclude: /node_modules/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              sourceMap: true,
              importLoaders: 1
            }
          },
          'postcss-loader'
        ]
      },
      {
        test: /\.pug/,
        exclude: /node_modules/,
        use: 'pug-loader'
      },
      {
        test: /.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
        exclude: /node_modules/,
        use: 'file-loader'
      }
    ]
  },
  watch: true,
  watchOptions: {
    ignored: /node_modules/
  },
  devServer: {
    contentBase: path.resolve(__dirname, '../public/'),
    port: appConfig.DEV_PORT,
    historyApiFallback: true
  },
  devtool: 'source-map',
  optimization: {
    runtimeChunk: 'single',
    splitChunks: {
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: 'manifest',
          chunks: 'all'
        }
      }
    }
  },
  plugins: [
    new ExtractTextPlugin(`../styles/${appConfig.OUTPUT_NAME}.[name].${appConfig.VERSION}.css`),
    new CopyWebpackPlugin([
      { from: '../src/assets', to: path.resolve(__dirname, '../public/assets') },
      { from: '../src/content', to: path.resolve(__dirname, '../public/content') }
    ]),
    new HtmlWebpackPlugin({ 'template': '../index.pug' })
  ]
};

module.exports = config;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-05 18:58:37

与其试图摆脱导致Internet 11不兼容问题的库,我建议在运行时使用一个为Array.includes()这样的有问题的API添加支持的polyfill。

可能最流行的解决方案是巴贝尔聚脂填料

您可以通过将以下脚本标记添加到页面的HTML代码中来使用它:

代码语言:javascript
复制
    <script nomodule src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js" integrity="sha256-WRc/eG3R84AverJv0zmqxAmdwQxstUpqkiE+avJ3WSo=" crossorigin="anonymous"></script>

注意,这个属性模式,这是为了确保只有不支持ES2015模块的浏览器才会实际加载这个多边形填充--即IE11。

现代浏览器(Chrome、Firefox、Safari等)只会忽略脚本标签,而不会给用户带来额外的下载负担。

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

https://stackoverflow.com/questions/53160188

复制
相关文章

相似问题

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