问题
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...
回答1:
Use -x [Module Name]
to exclude node modules from the bundle.
browserify -d -x react -x react-router app.js > bundle.js
来源:https://stackoverflow.com/questions/30965909/how-to-remove-change-some-require-calls-when-using-browserify