How to enable browser transform in only one environment

I have a project layout like this:

gulpfile.js
node_modules/
    foo/
    bar/

      

Where the modules foo/

and bar/

in fact my own code, for which I want to apply Browserify conversion. (This is a hack to avoid relative paths such as require("../../blah")

can be written instead require("foo/pkg/blah")

.)

Because of the way Browserify works, I need to have a file in package.json

both foo / and bar / modules, with content like this:

{
  "browserify": {
    "transform": ["rewireify"]
  }
}

      

Otherwise Browserify will only apply the transform to the root module, not to the submodules.

But I would like to apply the transform rewireify

only when the tests are running (it adds dependency injection code to every module that I don't want to include in the assembly).

But disabling rewireify

top-level transform does not affect submodules.

Is there a way to enable some Browserify transforms in some environment only? Or maybe a way to enable only some package.json

environment based settings ?

PS. I found a workaround by hacking the transform source rewireify

, but it would be nice to achieve it so that I don't need to transform the transform.

+3


source to share





All Articles