在package.json中声明时,Reactify转换不运行 [英] Reactify transform not running when declared in package.json

查看:136
本文介绍了在package.json中声明时,Reactify转换不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这个吞咽任务的工作原理:

pre> return browserify({
paths:['./node_modules','/app/scripts/'],
entries:['./app/
transform:['reactify'],
debug:true
})
.bundle()
.pipe(source( 'bundle.js'))
.pipe(gulp.dest('。tmp / scripts /'));

如果我从gulp中移除变换键并将其移动到package.json:

 browserify:{
transform:[
[reactify,{es6:true}]]




$ b $变换不再运行(也可以在没有es6的情况下尝试) 。



我使用这个yeoman生成器: https://www.npmjs.org/package/generator-react-spa



任何人都可以解释吗?

解决方案

使用package.json中的配置有两种情况:


  • 您使用browserify命令行工具

  • 它是一个不同于当前版本的软件包(例如,您需要时会使用react的package.json配置)



如果您使用的是API,您可以手动指定变换。为避免重复:

  var package = require('./ package.json'); 
browserify({
paths:['./node_modules','/app/scripts/'],
entries:['./app/scripts/index.js'],
transform:package.browserify.transform,
debug:true
})

或更一般地说,这里,合并可以是你最喜欢的合并实现(例如 _.defaults ) / p>

  browserify(合并({},package.browserify.transform,{
paths:['./node_modules', './app/scripts/'],
条目:['./app/scripts/index.js'],
debug:true
}))


I'm trying to use the reactify transform with browserify and gulp.

This gulp task works:

return browserify({
        paths: ['./node_modules','./app/scripts/'],
        entries: ['./app/scripts/index.js'],
        transform: ['reactify'],
        debug: true
    })
    .bundle()
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('.tmp/scripts/'));

If i remove the transform key from gulp and move it to package.json:

  "browserify": {
    "transform": [
      ["reactify", {"es6": true}]
    ]
  }

The transform no longer runs (also tried without es6).

I'm using this yeoman generator: https://www.npmjs.org/package/generator-react-spa

Can anyone please explain?

解决方案

The config in package.json is used in two situations:

  • you use the browserify command line tool
  • it's a package other than the current (e.g. react's package.json config is used when you require it)

If you're using the api, you manually specify transforms. To avoid repeating yourself:

var package = require('./package.json');
browserify({
        paths: ['./node_modules','./app/scripts/'],
        entries: ['./app/scripts/index.js'],
        transform: package.browserify.transform,
        debug: true
})

or more generally this, where merge can be your favorite merge implementation (e.g. _.defaults)

browserify(merge({}, package.browserify.transform, {
        paths: ['./node_modules','./app/scripts/'],
        entries: ['./app/scripts/index.js'],
        debug: true
}))

这篇关于在package.json中声明时,Reactify转换不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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