forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.js
More file actions
114 lines (89 loc) · 2.67 KB
/
webpack.js
File metadata and controls
114 lines (89 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var path = require("path");
// Local version replace global one
try {
var localWebpack = require.resolve(path.join(process.cwd(), "node_modules", "webpack", "bin", "webpack.js"));
if(__filename != localWebpack) {
return require(localWebpack);
}
} catch(e) {}
var fs = require("fs");
var util = require("util");
var optimist = require("optimist")
.usage("webpack " + require("../package.json").version + "\n" +
"Usage: https://github.com/webpack/docs/wiki/webpack-detailed-usage")
require("./config-optimist")(optimist);
optimist
.boolean("json").alias("json", "j").describe("json")
.boolean("colors").alias("colors", "c").describe("colors")
.string("sort-modules-by").describe("sort-modules-by")
.string("sort-chunks-by").describe("sort-chunks-by")
.string("sort-assets-by").describe("sort-assets-by")
.boolean("display-chunks").describe("display-chunks")
.boolean("display-reasons").alias("display-reasons", "verbose").alias("display-reasons", "v").describe("display-reasons");
var argv = optimist.argv;
var options = require("./convert-argv")(optimist, argv);
function ifArg(name, fn, init) {
if(Array.isArray(argv[name])) {
if(init) init();
argv[name].forEach(fn);
} else if(typeof argv[name] != "undefined") {
if(init) init();
fn(argv[name], -1);
}
}
var outputOptions = {
cached: false,
context: options.context
};
ifArg("json", function(bool) {
outputOptions.json = bool;
});
ifArg("colors", function(bool) {
outputOptions.colors = bool;
});
ifArg("sort-modules-by", function(value) {
outputOptions.modulesSort = value;
});
ifArg("sort-chunks-by", function(value) {
outputOptions.chunksSort = value;
});
ifArg("sort-assets-by", function(value) {
outputOptions.assetsSort = value;
});
if(!outputOptions.json) {
ifArg("display-chunks", function(bool) {
outputOptions.modules = !bool ;
outputOptions.chunks = bool;
});
ifArg("display-reasons", function(bool) {
outputOptions.reasons = bool;
});
} else {
outputOptions.chunks = true;
outputOptions.modules = true;
outputOptions.chunkModules = true;
outputOptions.reasons = true;
}
var webpack = require("../lib/webpack.js");
Error.stackTrackLimit = 30;
webpack(options, function(err, stats) {
if(err) {
console.error(err.stack || err);
return;
}
if(outputOptions.json)
process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
else {
process.stdout.write(stats.toString(outputOptions) + "\n");
}
if(!options.watch) {
// Do not keep cache anymore
var ifs = stats.compilation.compiler.inputFileSystem;
if(ifs && ifs.purge) ifs.purge();
}
});