Reactify transform doesn't work when declared in package.json

I am trying to use reactify transform with browser 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 conversion doesn't work anymore (also tried without es6).

I am using this youma generator: https://www.npmjs.org/package/generator-react-spa

Can someone please explain?

+3


source to share


2 answers


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

  • you are using the browser command line tool
  • this is a package other than the current one (for example, response package.json config is used when you require it)

If you are using 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 is where merge might 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
}))

      

+3


source


Perhaps it shouldn't work like this? That is, the browserify command does not read your own package.json, only the required modules (?).

https://github.com/substack/node-browserify#browserifytransform



Now, when someone requests () s of your module, brfs will be automatically applied to files in your module without explicit intervention from the person using your module.

+1


source







All Articles