Babel polyfill with webpack

99封情书 提交于 2019-12-06 06:11:35

问题


Do I need to include import "babel-polyfill" to the top of each entry file, or is it enough to have babel-polyfill rule just in webpack.config file? I am confused by polyfill docs and still getting following error: only one instance of babel-polyfill is allowed

My webpack.config in short:

  entry1: ['babel-polyfill', 'homepage.js'],
  entry2: ['babel-polyfill', 'not-homepage.js'],
  entry3: ['babel-polyfill', 'contacts.js']

回答1:


You are getting the error because you are calling multiple instances of the babel-polyfill.

You can choose any of the two option, but not both.

If you use webpack, don't put separate entries pointing to separate files, but rather point to a directory.

E.g: If your files are in app/js

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

If you decide to import it, make sure you import/require it only once at the entry-point to your application, before anything else is called.



来源:https://stackoverflow.com/questions/38118210/babel-polyfill-with-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!