如何在React脚本中生成ES6模块

时间:2019-07-15 13:22:39

标签: reactjs webpack ecmascript-6 babel react-scripts

我正在尝试生成ES6模块而不是ES5。根据{{​​3}}的文章,我在目标中添加了浏览器,但仍然生成了ES5模块。我做错了什么,如何生成ES6模块?

const rewire = require('rewire');
const defaults = rewire('react-scripts/scripts/build.js');

let config = defaults.__get__('config');

config.optimization.splitChunks = {
  name: true,
  chunks: 'initial',
  cacheGroups:
    {
      default: false
    },
  };
config.optimization.runtimeChunk = false;
config.module.rules[2].oneOf[1].options.plugins.push(['lodash']);
// LESS processors
const defaultRules = config.module.rules;

// Find object which has oneOf
// OR get the last object -> coz this is recommended to have fileLoader as the last option
const loaderOptions = defaultRules[defaultRules.length - 1];

loaderOptions.oneOf[2].options.presets[0][1] = {
  ...loaderOptions.oneOf[2].options.presets[0][1],
  targets: {
    browsers: [
      'Chrome >= 60',
      'Safari >= 10.1',
      'iOS >= 10.3',
      'Firefox >= 54',
      'Edge >= 15',
    ]
  }
}

0 个答案:

没有答案