避免使用 Browserify 捆绑特定模块
Avoid bundling specific modules with Browserify
我有一个这样的依赖树:
index.js
\__ A
\__ B
\__ C
| \__ D
\__ E
我想捆绑 index.js
并且效果很好:browserify --node index.js -o bundle.js
问题是其中一个依赖项具有依赖项。假设它是 D
具有本机依赖项(C++ 代码)。
我想使用 npm install D
手动安装它,并使 bundle.js
真正需要它来自磁盘,而不是来自 bundle.js
代码。
如何从捆绑包中排除 D
模块并使捆绑包从 node_modules
中需要它?
我尝试使用 --ignore D
,但在需要时它 returns 是一个空对象。
如何从 node_modules
目录中 require
一个真正的模块(就像 Node 的 require
一样?
将 --exclude
选项与 --node
一起使用:
browserify --node -s GlobalVariable your-script.js -o bundle.js --exclude some-dependency
这将创建 bundle.js
文件,如果没有 CommonJS 环境,该文件将定义 GlobalVariable
变量。
--node
如果您想 运行 在 Node 中而不是在浏览器中打包,
是一个方便的选项。
--exclude
选项将从输出包中排除 some-dependency
模块。
查看 Browserify Usage 部分。
我有一个这样的依赖树:
index.js
\__ A
\__ B
\__ C
| \__ D
\__ E
我想捆绑 index.js
并且效果很好:browserify --node index.js -o bundle.js
问题是其中一个依赖项具有依赖项。假设它是 D
具有本机依赖项(C++ 代码)。
我想使用 npm install D
手动安装它,并使 bundle.js
真正需要它来自磁盘,而不是来自 bundle.js
代码。
如何从捆绑包中排除 D
模块并使捆绑包从 node_modules
中需要它?
我尝试使用 --ignore D
,但在需要时它 returns 是一个空对象。
如何从 node_modules
目录中 require
一个真正的模块(就像 Node 的 require
一样?
将 --exclude
选项与 --node
一起使用:
browserify --node -s GlobalVariable your-script.js -o bundle.js --exclude some-dependency
这将创建 bundle.js
文件,如果没有 CommonJS 环境,该文件将定义 GlobalVariable
变量。
--node
如果您想 运行 在 Node 中而不是在浏览器中打包,
--exclude
选项将从输出包中排除 some-dependency
模块。
查看 Browserify Usage 部分。