-
-
Notifications
You must be signed in to change notification settings - Fork 668
Expand file tree
/
Copy pathwebpack.js
More file actions
executable file
·174 lines (163 loc) · 4.43 KB
/
webpack.js
File metadata and controls
executable file
·174 lines (163 loc) · 4.43 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env node
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var path = require('path');
// var fs = require('fs');
// Local version replace global one
try {
var localWebpack = require.resolve(path.join(process.cwd(), 'node_modules', 'webpack-cli', 'bin', 'webpack.js'));
if(localWebpack && path.relative(localWebpack, __filename) !== '') {
return require(localWebpack);
}
} catch(e) {
/*
// Delete Cache, Retry and leave it if the path isn`t valid.
// swap with webpack-cli later
var dirPath = path.join(process.cwd(), 'node_modules', 'webpack', 'bin');
var retryLocal;
fs.readdir(dirPath, function(err, files) {
files.filter( (file) => {
delete require.cache[file];
});
// TODO: If path is wrong, leave it to higher powers until we publish on npm
// Could also install and load and install through github
return require(path.join(dirPath, 'webpack.js'))
});
*/
}
var yargs = require('yargs')
.usage('webpack-cli ' + require('../package.json').version + '\n' +
'Usage: https://webpack.github.io/docs/cli.html\n' +
'Usage without config file: webpack <entry> [<entry>] <output>\n' +
'Usage with config file: webpack');
require('./config-yargs')(yargs);
var DISPLAY_GROUP = 'Stats options:';
var BASIC_GROUP = 'Basic options:';
yargs.options({
'json': {
type: 'boolean',
alias: 'j',
describe: 'Prints the result as JSON.'
},
'progress': {
type: 'boolean',
describe: 'Print compilation progress in percentage',
group: BASIC_GROUP
},
'color': {
type: 'boolean',
alias: 'colors',
default: function supportsColor() {
return require('supports-color');
},
group: DISPLAY_GROUP,
describe: 'Enables/Disables colors on the console'
},
'sort-modules-by': {
type: 'string',
group: DISPLAY_GROUP,
describe: 'Sorts the modules list by property in module'
},
'sort-chunks-by': {
type: 'string',
group: DISPLAY_GROUP,
describe: 'Sorts the chunks list by property in chunk'
},
'sort-assets-by': {
type: 'string',
group: DISPLAY_GROUP,
describe: 'Sorts the assets list by property in asset'
},
'hide-modules': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Hides info about modules'
},
'display-exclude': {
type: 'string',
group: DISPLAY_GROUP,
describe: 'Exclude modules in the output'
},
'display-modules': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display even excluded modules in the output'
},
'display-chunks': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display chunks in the output'
},
'display-entrypoints': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display entry points in the output'
},
'display-origins': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display origins of chunks in the output'
},
'display-cached': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display also cached modules in the output'
},
'display-cached-assets': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display also cached assets in the output'
},
'display-reasons': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display reasons about module inclusion in the output'
},
'display-used-exports': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display information about used exports in modules (Tree Shaking)'
},
'display-provided-exports': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display information about exports provided from modules'
},
'display-error-details': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Display details about errors'
},
'verbose': {
type: 'boolean',
group: DISPLAY_GROUP,
describe: 'Show more details'
}
});
var argv = yargs.argv;
if(argv.verbose) {
argv['display-reasons'] = true;
argv['display-entrypoints'] = true;
argv['display-used-exports'] = true;
argv['display-provided-exports'] = true;
argv['display-error-details'] = true;
argv['display-modules'] = true;
argv['display-cached'] = true;
argv['display-cached-assets'] = true;
}
var processOptions = require('./process-options');
var initInquirer = require('../lib/initialize');
if(argv.init) {
initInquirer(argv._);
} else if(argv.migrate) {
const filePaths = argv._;
if (!filePaths.length) {
throw new Error('Please specify a path to your webpack config');
}
const inputConfigPath = path.resolve(process.cwd(), filePaths[0]);
require('../lib/migrate.js')(inputConfigPath, inputConfigPath);
} else {
processOptions(yargs,argv);
}