简体   繁体   中英

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?

From: browserify test.js -u request > test.browserify.js
To: browserify test.js > test.browserify.js

Potential solutions:

  1. --exclude has a package.json option similiar to --ignore: "browser": { "request": false }
  2. --exclude can be enabled, or its functionality copied, using "transform" somehow "browserify": {"transform": ...}
  3. ...

Found a solution:

Add the following to package.json: "browser": { "request": "./request.js" }

Create ./request.js and put the following in it:

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM