如何“删除” /“更改”?使用browserify时需要一些require(...)调用? [英] How to "remove"/"change" some require(...) calls when using browserify?

查看:64
本文介绍了如何“删除” /“更改”?使用browserify时需要一些require(...)调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用node.js编写的应用程序,它需要一些npm模块(反应,反应路由器等)。当我在上面运行browserify时,所有npm模块都被注入到bundle.js文件中。我想要的是为bower提供分发包,该分发包在bundle.js文件中不包含react和react-router依赖项,因为它们可以在bower.json中被引用为依赖项。

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(...)

在bundle.js中,react和app.js一起注入了

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

我需要不包含react的bundle.js,并假定它在全局(窗口)范围内可用。

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

bundle .js:

bundle.js:

React.render(...)

或类似这样的东西:

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

所以基本上我想告诉browserify某些模块可以在 window 范围内找到,而不必注入进入bundle.js ...

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...

推荐答案

使用 -x [Module Name] 从捆绑中排除节点模块。

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

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

这篇关于如何“删除” /“更改”?使用browserify时需要一些require(...)调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆