简体   繁体   English

Browserify:如何使用package.json应用“ --exclude,-u”?

[英]Browserify: How do I apply “--exclude, -u” using package.json?

I need to use --exclude, -u within package.json rather then as a command line option, but how? 我需要在package.json中使用--exclude, -u而不是作为命令行选项,但是如何?

From: browserify test.js -u request > test.browserify.js 来自: browserify test.js -u request > test.browserify.js
To: browserify test.js > test.browserify.js 发送至: browserify test.js > test.browserify.js

Potential solutions: 潜在的解决方案:

  1. --exclude has a package.json option similiar to --ignore: "browser": { "request": false } --exclude具有与--ignore类似的package.json选项: "browser": { "request": false }
  2. --exclude can be enabled, or its functionality copied, using "transform" somehow "browserify": {"transform": ...} --exclude可以使用“ transform”以某种方式"browserify": {"transform": ...}来启用或复制其功能"browserify": {"transform": ...}
  3. ... ...

Found a solution: 找到一个解决方案:

Add the following to package.json: "browser": { "request": "./request.js" } 将以下内容添加到package.json: "browser": { "request": "./request.js" }

Create ./request.js and put the following in it: 创建./request.js并将以下内容放入其中:

var req = "request";
module.exports = require(req);

And you have to put the "request" string in a separate variable, if you don't the require will just return an empty object stub {} . 并且您必须将“ request”字符串放在一个单独的变量中,如果不这样做,则require将仅返回一个空的对象存根{}

The downside of this is that I have to define such a file for every module I want to require, ideally I'd have a single file that can detect what to require. 缺点是我必须为每个需要的模块定义一个文件,理想情况下,我将有一个文件来检测需要的文件。

Edit 编辑

Haven't tested this yet but I could probably dynamically require these modules without an external file var req = "request"; var request = require(req); 还没有测试过,但是我可能会动态地需要这些模块而无需外部文件var req = "request"; var request = require(req); var req = "request"; var request = require(req);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在package.json中指定browserify扩展? - How to specify browserify extensions in package.json? 如何自动更新 package.json 中的条目? - How do I update the entries in package.json automatically? 如何使用流星添加更新package.json? - How can I update the package.json using meteor add? 使用带有grunt-browserify的shimmed package.json缓存的CKEditor资产 - CKEditor assets cached using shimmed package.json with grunt-browserify Browserify-在符号链接模块上的package.json中转换在npm3中不起作用 - Browserify - transform in package.json on symlinked modules not working in npm3 Yarn Workspaces和Browserify - 子文件夹中的package.json会破坏构建 - Yarn Workspaces and Browserify - package.json in subfolder breaks the build 当新安装的模块没有出现在 package.json “依赖项”列表中时,如何在 React 中使用它们? - How do I use newly installed modules in React when they do not appear in the package.json "dependencies" list? 如何向运行 javascript 文件的 package.json 文件添加自定义脚本? - How do I add a custom script to my package.json file that runs a javascript file? 在 package.json 脚本中,我如何将参数传递给 node,而不是脚本? - In a package.json script, how do I pass an argument to node, as opposed to the script? 如何将 package.json 与单独的文件(在本例中为 nodemon.app)链接 - How do I link package.json with a separate file (in this case nodemon.app)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM