user606521
user606521

Reputation: 15434

How to "remove"/"change" some require(...) calls when using browserify?

I have app written in node.js that requires some npm modules (react, react-router and others). When I run browserify on it, then all npm modules are "injected" to the bundle.js file. What I want is to provide distribution for bower that won't include react and react-router dependencies in bundle.js file, because they can be referenced as dependencies in bower.json.

app.js:

var React = require('react')
React.render(...)

In bundle.js react is injected into it along with app.js

I need bundle.js that will not contain react and will assume that it is available in global (window) scope.

bundle.js:

React.render(...)

or something like this:

var require = function(name){ return window[name] }
var React = require('react')
React.render(...)

So basically I want to tell browserify that SOME of the modules can be found in window scope and don't have to be injected in to the bundle.js...

Upvotes: 2

Views: 1267

Answers (1)

marcel
marcel

Reputation: 3149

Use -x [Module Name] to exclude node modules from the bundle.

browserify -d -x react -x react-router app.js > bundle.js

Upvotes: 1

Related Questions