nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 50 forks source link

Use global transforms #209

Closed DigitalFlow closed 7 years ago

DigitalFlow commented 7 years ago

Hey everyone,

thanks for this framework, it helped me making a huge step forward for my project quality.

There's one thing that I can't find out how to configure: I have some transitive dependencies (I don't require them, but my dependencies do), which have fs.readFileSync calls in them. So to get rid of them, I run brfs on it.

In my package.json, my task looks as follows:

    "build-js": "browserify -g brfs src/js/WebApiClient.js -s WebApiClient -o Publish/WebApiClient.js",

I have to use the -g flag for my transform, otherwise brfs would not be executed on my transitive dependencies.

In my karma.conf.js I have the following browserify configuration right now:

browserify: {
                debug: true,
                transform: [ 'brfs', istanbul({
                    ignore: ['**/node_modules/**', '**/spec/**']
                })]
      }

This however behaves just like the "normal" transform, so my transitive dependencies are not transformed like this. I read that you can pass browserify options just like the "debug" option above, but I did not succeed on doing this for the -g / --global-transform=MODULE option.

Any help on this would be greatly appreciated.

Kind Regards, Florian

bendrucker commented 7 years ago

See https://github.com/nikku/karma-browserify#transforms

Use {global: true}, not a karma-browserify thing, it's just passed along to browserify and handled there.

DigitalFlow commented 7 years ago

Hey @bendrucker,

thanks for your answer.

For anyone having the same issue in the future, this is what worked for me:

    browserify: {
                debug: true,
                transform: [ ['brfs', {global: true}], istanbul({
                    ignore: ['**/node_modules/**', '**/spec/**']
                })]
      }
bendrucker commented 7 years ago

FYI that's not subargs, this is:

browserify -t [ foo --bar=555 ] main.js

https://www.npmjs.com/package/subarg

DigitalFlow commented 7 years ago

Sorry, you're right. Fixed it.