Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle external dependencies #16

Open
nickdima opened this issue Feb 16, 2014 · 2 comments
Open

Bundle external dependencies #16

nickdima opened this issue Feb 16, 2014 · 2 comments
Labels

Comments

@nickdima
Copy link

In my project I'm using both npm modules and bower components (with debowerify) which I want to bundle together as vendor.js while keeping my own code in an app.js bundle.

What I did so far is created the app.js bundle by setting external to the npm modules and bower components. To figure out what modules to set as external I read the dependencies from package.json and bower.json.

Now, in a similar fashion I would like to parse my codebase, see which requires are external modules and bundle them together.
How could I do this?

@mykone
Copy link

mykone commented Jul 14, 2016

Hello, anybody have a solution to the question above? I know it's very old, but I am now starting to use factor-bundle, and I am facing the same situation.

@casr
Copy link

casr commented Apr 29, 2017

Factor Bundle has the ability to run a custom filter via the threshold option. So you could do:

#!/usr/bin/env node
var browserify = require('browserify')
var fs = require('fs')
var path = require('path')

var entries = [
  path.join(__dirname, 'index.js')
]

var outputFiles = [
  path.join(__dirname, 'dist-main.js')
]

var b = browserify(entries)

b.plugin('factor-bundle', {
  output: outputFiles,
  threshold: function (row, groups) {
    // Get a relative directory to where we are building
    var rPath = path.relative(__dirname, row.file)

    // Assuming our node_modules folder is in the same directory that we are
    // building in then just declare vendor files as those presiding in it
    return !!rPath.match(/^node_modules\//)
  }
})

b.bundle().pipe(fs.createWriteStream(path.join(__dirname, 'dist-vendor.js')))

I've made a simple repository showing it all together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants