FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add cli support for --transform-key to support mode's like production… · browserify/browserify@d7ff52d · GitHub

Repository navigation

Commit d7ff52d

Browse files
committed
add cli support for --transform-key to support mode's like production/staging/etc..
1 parent a5aa660 commit d7ff52d

3 files changed

Lines changed: 45 additions & 27 deletions

File tree

‎bin/advanced.txt‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Advanced Options:
44

55
Skip detection and always insert definitions for process, global,
66
__filename, and __dirname.
7-
7+
88
benefit: faster builds
99
cost: extra bytes
10-
10+
1111
--insert-global-vars, --igv
1212

1313
Comma-separated list of global variables to detect and define.
1414
Default: __filename,__dirname,process,Buffer,global
15-
15+
1616
--detect-globals, --dg [default: true]
1717

1818
Detect the presence of process, global, __filename, and __dirname and define
@@ -36,16 +36,16 @@ Advanced Options:
3636
provides the core builtins.
3737

3838
--no-commondir
39-
39+
4040
Turn off setting a commondir. This is useful if you want to preserve the
41-
original paths that a bundle was generated with.
42-
41+
original paths that a bundle was generated with.
42+
4343
--no-bundle-external
4444

4545
Turn off bundling of all external modules. This is useful if you only want
4646
to bundle your local files.
4747

48-
--bare
48+
--bare
4949

5050
Alias for both --no-builtins, --no-commondir, and sets --insert-global-vars
5151
to just "__filename,__dirname". This is handy if you want to run bundles in
@@ -56,6 +56,15 @@ Advanced Options:
5656
Turn off package.json browser field resolution. This is also handy if you
5757
need to run a bundle in node.
5858

59+
--transform-key
60+
61+
Instead of the default package.json#browserify#transform field to list
62+
all transforms to apply when running browserify, a custom field, like, e.g.
63+
package.json#browserify#production or package.json#browserify#staging
64+
can be used, by for example running:
65+
* `browserify index.js --transform-key=production > bundle.js`
66+
* `browserify index.js --transform-key=staging > bundle.js`
67+
5968
--node
6069

6170
Alias for --bare and --no-browser-field.
@@ -66,7 +75,7 @@ Advanced Options:
6675
preserving the original paths that a bundle was generated with.
6776

6877
--deps
69-
78+
7079
Instead of standard bundle output, print the dependency array generated by
7180
module-deps.
7281

@@ -75,7 +84,7 @@ Advanced Options:
7584
Turn off deduping.
7685

7786
--list
78-
87+
7988
Print each file in the dependency graph. Useful for makefiles.
8089

8190
--extension=EXTENSION
@@ -101,4 +110,3 @@ Passing arguments to transforms and plugins:
101110
will call the `foo` transform for each applicable file by calling:
102111

103112
foo(file, { x: 3, beep: true })
104-

‎bin/args.js‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = function (args, opts) {
5151
node: false
5252
}
5353
});
54-
54+
5555
var entries = argv._.concat(argv.entry)
5656
.filter(Boolean).map(function (entry) {
5757
if (entry === '-') {
@@ -64,7 +64,7 @@ module.exports = function (args, opts) {
6464
}
6565
return entry;
6666
});
67-
67+
6868
if (argv.node) {
6969
argv.bare = true;
7070
argv.browserField = false;
@@ -76,7 +76,7 @@ module.exports = function (args, opts) {
7676
argv.igv = '__filename,__dirname';
7777
}
7878
}
79-
79+
8080
if (argv.igv) {
8181
var insertGlobalVars = {};
8282
var wantedGlobalVars = argv.igv.split(',');
@@ -86,12 +86,12 @@ module.exports = function (args, opts) {
8686
}
8787
});
8888
}
89-
89+
9090
var ignoreTransform = argv['ignore-transform'] || argv.it;
9191
var b = browserify(xtend({
9292
noParse: Array.isArray(argv.noParse) ? argv.noParse : [argv.noParse],
9393
extensions: [].concat(argv.extension).filter(Boolean).map(function (extension) {
94-
if (extension.charAt(0) != '.') {
94+
if (extension.charAt(0) != '.') {
9595
return '.' + extension;
9696
} else {
9797
return extension
@@ -105,6 +105,7 @@ module.exports = function (args, opts) {
105105
bundleExternal: argv['bundle-external'],
106106
basedir: argv.basedir,
107107
browserField: argv.browserField,
108+
transformKey: argv['transform-key'] ? ['browserify', argv['transform-key']] : undefined,
108109
dedupe: argv['dedupe'],
109110

110111
detectGlobals: argv.detectGlobals,
@@ -128,7 +129,7 @@ module.exports = function (args, opts) {
128129
b.plugin(pf, pOpts);
129130
})
130131
;
131-
132+
132133
[].concat(argv.ignore).filter(Boolean)
133134
.forEach(function (i) {
134135
b._pending ++;
@@ -144,11 +145,11 @@ module.exports = function (args, opts) {
144145
});
145146
})
146147
;
147-
148+
148149
[].concat(argv.exclude).filter(Boolean)
149150
.forEach(function (u) {
150151
b.exclude(u);
151-
152+
152153
b._pending ++;
153154
glob(u, function (err, files) {
154155
if (err) return b.emit('error', err);
@@ -164,7 +165,7 @@ module.exports = function (args, opts) {
164165
b.require(xs[0], { expose: xs.length === 1 ? xs[0] : xs[1] })
165166
})
166167
;
167-
168+
168169
// resolve any external files and add them to the bundle as externals
169170
[].concat(argv.external).filter(Boolean)
170171
.forEach(function (x) {
@@ -181,26 +182,26 @@ module.exports = function (args, opts) {
181182
});
182183
}
183184
else add(x, {});
184-
185+
185186
function add (x, opts) {
186187
if (/^[\/.]/.test(x)) b.external(path.resolve(x), opts)
187188
else b.external(x, opts)
188189
}
189190
})
190191
;
191-
192+
192193
[].concat(argv.transform)
193194
.filter(Boolean)
194195
.forEach(function (t) { addTransform(t) })
195196
;
196-
197+
197198
[].concat(argv.g).concat(argv['global-transform'])
198199
.filter(Boolean)
199200
.forEach(function (t) {
200201
addTransform(t, { global: true });
201202
})
202203
;
203-
204+
204205
function addTransform (t, opts) {
205206
if (typeof t === 'string' || typeof t === 'function') {
206207
b.transform(opts, t);
@@ -218,7 +219,7 @@ module.exports = function (args, opts) {
218219
}
219220
else error('unexpected transform of type ' + typeof t);
220221
}
221-
222+
222223
[].concat(argv.command).filter(Boolean)
223224
.forEach(function (c) {
224225
var cmd = parseShell(c);
@@ -231,7 +232,7 @@ module.exports = function (args, opts) {
231232
var ps = spawn(cmd[0], cmd.slice(1), { env: env });
232233
var error = '';
233234
ps.stderr.on('data', function (buf) { error += buf });
234-
235+
235236
ps.on('exit', function (code) {
236237
if (code === 0) return;
237238
console.error([
@@ -245,12 +246,12 @@ module.exports = function (args, opts) {
245246
});
246247
})
247248
;
248-
249+
249250
if (argv.standalone === '') {
250251
error('--standalone requires an export name argument');
251252
return b;
252253
}
253-
254+
254255
return b;
255256
};
256257

‎readme.markdown‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ Advanced Options:
164164
Turn off package.json browser field resolution. This is also handy if you
165165
need to run a bundle in node.
166166
167+
--transform-key
168+
169+
Instead of the default package.json#browserify#transform field to list
170+
all transforms to apply when running browserify, a custom field, like, e.g.
171+
package.json#browserify#production or package.json#browserify#staging
172+
can be used, by for example running:
173+
* `browserify index.js --transform-key=production > bundle.js`
174+
* `browserify index.js --transform-key=staging > bundle.js`
175+
167176
--node
168177
169178
Alias for --bare and --no-browser-field.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL