简体   繁体   English

如何使用webpack 2进行polyfill fetch和promise?

[英]How to polyfill fetch and promise with webpack 2?

How to polyfill fetch and promise for Webpack 2 ? 如何对Webpack 2进行polyfill fetchpromise

I have a lot of entry points, so Webpack 1-way to add them before each entry point is not desired solution. 我有很多入口点,所以Webpack在每个入口点之前添加它们的方法不是理想的解决方案。

Regardless of how many entry points you have, you should have a separate file for your vendor files, such as frameworks (react, angular, whatevs) and any libraries you always need but are rarely going to change. 无论您拥有多少入口点,您都应该为供应商文件提供单独的文件,例如框架(react,angular,whatevs)以及您始终需要但很少会更改的任何库。 You want those as a separate bundle so you can cache it. 您希望这些作为单独的捆绑包,以便您可以缓存它。 That bundle should always be loaded. 应始终加载该捆绑包。 Anything you include in that bundle will always be available but never repeated in your chunks if you use it with the commonChunksPlugin. 您在该捆绑包中包含的任何内容将始终可用,但如果您将其与commonChunksPlugin一起使用,则不会在您的块中重复。

Here's a sample from an app I've done (just showing relevant config options): 这是我已经完成的应用程序的示例(只显示相关的配置选项):

module.exports = {
  entry: {
    client: 'client',
    vendor: [
      'react',
      'react-addons-shallow-compare',
      'react-addons-transition-group',
      'react-dom',
      'whatwg-fetch'
    ]
  },
  output: {
    path: `${__dirname}/dist`,
    filename: '[name].js',
    publicPath: '/build/'
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      names: ['vendor', 'manifest']
    })
  ]
}

Maybe I'm not understanding correctly, but couldn't you just add babel-polyfill before the rest of your entry points in your webpack config? 也许我没有正确理解,但你不能在你的webpack配置中的其他入口点之前添加babel-polyfill polyfill吗?

module.exports = {
   entry: ['babel-polyfill', './app/js', '/app/js/whatever']
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM