caleb / broccoli-fast-browserify

A caching, flexible Browserify Broccoli filter
https://github.com/caleb/broccoli-fast-browserify
BSD 3-Clause "New" or "Revised" License
14 stars 7 forks source link

debug my quirky setup - or not: Seperating own code and 3rd party code #14

Closed ccoenen closed 8 years ago

ccoenen commented 8 years ago

Disclaimer: this may be an odd setup. I am not offended if you don't find the time debugging my quirky setup. In that case: please feel free to close this issue on sight ;-)

I would like to have two output files. One should contain all the 3rd party libs from NPM and one should contain my "personal" code. My index.html file contains two script tags, one for npm.js and one for app.js.

Right now, i process a npm.browserify file through broccoli-fast-browserify (bfb from now on). And i process my own code through a combination of other thins but not through bfb. I made this work by exposing the require function to the window scope.

The downside is, that i have to manually require all my libs in the npm.browserify by hand, so that they can be picked up. I would love to make this setup work "right". Especially because the manual dual-require is error-prone. Also, the window.require = require doesn't feel "right".

ccoenen commented 8 years ago

this is what i came up with:

// Brocfile.js
var packagejson = require('./package.json');
var thirdPartyNPMLibs = Object.keys(packagejson.dependencies); // awesome: just put it in package.json, and it's there :)
appJs = fastBrowserify(appJs, {
  browserify: {
    debug: true
  },
  bundles: {
    'app.js': {
      entryPoints: ['app.js'],
      externals: thirdPartyNPMLibs // <-- these will not be in app.js
    },
    'npm.js': {
      entryPoints: [],
      require: thirdPartyNPMLibs // <-- instead, they will be in npm.js, a file with no entryPoint :)
    }
  }
});
ccoenen commented 8 years ago

that last one is now separated in two distinct calls to fastBrowserify(), and one gets a WatchedDir and the other an UnwatchedDir - i'm happy.

caleb commented 8 years ago

This would be a nice wiki entry as I'm sure it's something that other people will want to do.

caleb commented 8 years ago

@ccoenen I created a wiki entry for this:

https://github.com/caleb/broccoli-fast-browserify/wiki/Separate-app-and-3rd-party-bundles

Do you think that looks good?

ccoenen commented 8 years ago

It looks almost like mine! Thank you!