Search code examples
javascriptbrowserify

Using Browserify with a config file instead of long CLI command


For Babel there is a .babelrc file, which contains all parameters needed for Babel to work, so you can just use babel index.js and this is working like specified in .babelrc, for example:

// .babelrc file { "presets": ["react"] }

smroot@whatever: ~/project $ babel index.js

works the same way as:

smroot@whatever: ~/project $ babel index.js --presets react

Is there something similar to this for Browserify, so:

smroot@whatever: ~/project $ browserify index.js -o bundle/index.js -t [ babelify --presets [ react ] ]

could be replaced with just:

smroot@whatever: ~/project $ browserify index.js

and a config file for this?


Solution

  • As @azium suggests in the comment you could create a npm script to handle this.

    Open you package.json file and find (or create) the scripts section.

    Then insert the command here with some name you would like.

    "scripts": {
      "browserify": "browserify index.js -o bundle/index.js -t [ babelify --presets [ react ] ]"
    }
    

    You can now run it with npm run browserify

    Otherwise you could use a task runner like gulp to handle this. In general if you have multiple tasks like running bable, browserify, sass, less, or need to move files around, an actual task runner might come in handy.