Babel 7不移植供应商块

时间:2018-11-08 17:53:45

标签: webpack babel

其他导入的库使用的某些模块正在使用const而不是var,并且生成的供应商块包含const,这会在较旧的浏览器上引发错误

SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

我的babel配置

  presets: [
    [
      '@babel/preset-env',
      {
        modules: false,
      },
    ],
    '@babel/preset-react',
  ],
  plugins: [
    '@babel/plugin-transform-runtime',
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-syntax-dynamic-import',
  ],
  env: {
    production: {
      only: ['app', 'ssr'],
      plugins: [
        'react-loadable/babel',
        'lodash',
        'transform-react-remove-prop-types',
        '@babel/plugin-transform-react-inline-elements',
        '@babel/plugin-transform-react-constant-elements',
      ],
    },
    test: {
      plugins: [
        '@babel/plugin-transform-modules-commonjs',
        'dynamic-import-node',
      ],
    },
  },

和webpack规则

  {
    test: /\.js$/,
    exclude: /node_modules/,
    use: {
      loader: 'babel-loader',
      options: Object.assign({
        sourceType: 'unambiguous',
      }),
    },
  },

0 个答案:

没有答案