Babel polyfill与webpack [英] Babel polyfill with webpack
问题描述
我需要将 importbabel-polyfill
包含在每个条目文件的顶部,还是足够让 babel-polyfill只需在webpack.config文件中定义
我被polyfill文档困惑,仍然收到以下错误:只允许一个babel-polyfill实例
我的webpack.config简而言之:
entry1:['babel-polyfill','homepage.js'],
pre>
entry2:['babel-polyfill','not-homepage.js'],
entry3:['babel-polyfill','contacts.js']
解决方案您正在收到错误,因为您正在调用babel-polyfill的多个实例。
您可以选择任何两个选项,但不能同时选择。
如果您使用webpack,请勿将单独的条目指向单独的文件,而是指向一个目录。
例如:如果您的文件在app / js中
module.exports = {
条目:[' babel-polyfill','./app/js']
};
如果您决定导入,请确保您导入/要求
$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $Do I need to include
import "babel-polyfill"
to the top of each entry file, or is it enough to havebabel-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']
解决方案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.
这篇关于Babel polyfill与webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!