[英]Avoid bundling specific modules with Browserify
I have a dependency tree like this: 我有一个像这样的依赖树:
index.js
\__ A
\__ B
\__ C
| \__ D
\__ E
I want to bundle index.js
and that works fine: browserify --node index.js -o bundle.js
我想捆绑index.js
,并且工作正常: browserify --node index.js -o bundle.js
The problem is when one of the dependencies has a dependency. 问题是当其中一个依赖项具有依赖项时。 Let's suppose it's D
that has a native dependency (C++ code). 让我们假设具有本地依赖项(C ++代码)的D
I want to install it manually using npm install D
and make the bundle.js
to really require it from the disk, not from the bundle.js
code. 我想使用npm install D
手动安装它,并使bundle.js
真正从磁盘而不是bundle.js
代码中获取它。
How can I exclude the D
module from the bundle and make the bundle to require it from the node_modules
? 如何将D
模块从包中排除,并使包从node_modules
要求它?
I tried using --ignore D
, but it returns an empty object when required. 我尝试使用--ignore D
,但是在需要时它返回一个空对象。
How can I require
a real module from the node_modules
directory (the way like Node's require
does? 我如何从node_modules
目录中require
一个真实的模块(就像Node的require
一样?
Use the --exclude
option together with --node
: 将--exclude
选项与--node
一起使用:
browserify --node -s GlobalVariable your-script.js -o bundle.js --exclude some-dependency
This will create the bundle.js
file which will define the GlobalVariable
variable if there is no CommonJS environment. 这将创建bundle.js
文件,如果没有CommonJS环境,它将定义GlobalVariable
变量。
--node
is a handy option if you want to run the bundle in Node, not in the browser. 如果要在Node(而不是浏览器)中运行捆绑软件,则--node
是一个方便的选项。
The --exclude
option will exclude the some-dependency
module from the output bundle. --exclude
选项将从输出包中排除some-dependency
模块。
Check out the Browserify Usage section. 查看“ 浏览器使用情况”部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.