Babel polyfill与webpack [英] Babel polyfill with webpack

查看:267
本文介绍了Babel polyfill与webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 importbabel-polyfill包含在每个条目文件的顶部,还是足够让 babel-polyfill只需在webpack.config文件中定义我被polyfill文档困惑,仍然收到以下错误:只允许一个babel-polyfill实例



我的webpack.config简而言之:

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

解决方案

您正在收到错误,因为您正在调用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 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']

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆