简体   繁体   English

使用babel-polyfill与grunt和browserify

[英]Using babel-polyfill with grunt and browserify

My grunt build system transpiles my javascript (which is using react as well). 我的grunt构建系统转换了我的javascript(也使用了反应)。 Unfortunately it doesn't transpile Promises. 不幸的是,它没有转变承诺。 For that, I need a polyfill. 为此,我需要一个polyfill。 I want to include babel-polyfill with my grunt build system. 我想在我的grunt构建系统中加入babel-polyfill。 My build system uses browserify along with babelify and the es2015 preset. 我的构建系统使用browserify以及babelify和es2015预设。

How do I include babel-polyfill into the mix? 如何在混合物中加入babel-polyfill?

Here is what I have... 这是我的......

Inside gruntfile.js, here is where I use browserify 在gruntfile.js里面,这里是我使用browserify的地方

browserify: {
  dist: {
    options: {
      watch: true,
      transform: [["babelify", {presets: ['es2015', 'react']}], ["envify", {NODE_ENV: 'development'}]]
    },
    files: {
      'dist/js/app.js' : 'src/js/main.js'
    }
  },
  build: {
    options: {
      transform: [["babelify", {presets: ['es2015', 'react'], compact: true }], ["envify", {NODE_ENV: 'production'}]]
    },
    files: {
      'dist/js/app.js' : 'src/js/main.js'
    }
  }
},

Here is my babelrc file 这是我的babelrc文件

{
 "presets": [ "react", "es2015" ]
}

Thanks! 谢谢!

Assuming that babel-polyfill is included as a dependency, at the top of your entry file 'src/js/main.js' add the line: 假设babel-polyfill作为依赖项包含在您的条目文件'src / js / main.js'的顶部添加以下行:

import "babel-polyfill";

No need to do anything in your GruntFile.js 无需在GruntFile.js中执行任何操作

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

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