webpack/bin/webpack.js

109 lines
2.5 KiB
JavaScript
Raw Normal View History

2012-03-10 13:11:23 +01:00
#!/usr/bin/env node
2012-03-11 21:50:55 +01:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2012-03-10 13:11:23 +01:00
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) {}
2012-03-10 13:11:23 +01:00
var fs = require("fs");
2012-03-15 00:05:29 +01:00
var util = require("util");
2013-01-30 18:49:25 +01:00
var optimist = require("optimist")
.usage("webpack " + require("../package.json").version + "\n" +
2013-01-30 18:49:25 +01:00
"Usage: https://github.com/webpack/docs/wiki/webpack-detailed-usage")
require("./config-optimist")(optimist);
2012-03-11 21:50:55 +01:00
2013-01-30 18:49:25 +01:00
optimist
2012-03-11 21:50:55 +01:00
2013-01-30 18:49:25 +01:00
.boolean("json").alias("json", "j").describe("json")
.boolean("colors").alias("colors", "c").describe("colors")
2012-03-11 21:50:55 +01:00
2013-01-30 18:49:25 +01:00
.string("sort-modules-by").describe("sort-modules-by")
2012-03-11 21:50:55 +01:00
2013-01-30 18:49:25 +01:00
.string("sort-chunks-by").describe("sort-chunks-by")
2012-03-11 21:50:55 +01:00
2013-01-30 18:49:25 +01:00
.string("sort-assets-by").describe("sort-assets-by")
2012-03-11 21:50:55 +01:00
2013-01-30 18:49:25 +01:00
.boolean("display-chunks").describe("display-chunks")
2013-01-30 18:49:25 +01:00
.boolean("display-reasons").alias("display-reasons", "verbose").alias("display-reasons", "v").describe("display-reasons");
var argv = optimist.argv;
2012-06-29 20:54:24 +02:00
2013-01-30 18:49:25 +01:00
var options = require("./convert-argv")(optimist, argv);
2012-04-03 16:26:08 +02:00
2013-01-30 18:49:25 +01:00
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);
}
2012-03-10 13:11:23 +01:00
}
2012-04-03 16:26:08 +02:00
2013-01-30 18:49:25 +01:00
var outputOptions = {
cached: false,
context: options.context
};
2012-06-29 20:54:24 +02:00
2013-01-30 18:49:25 +01:00
ifArg("json", function(bool) {
outputOptions.json = bool;
});
2012-05-01 21:33:59 +02:00
2013-01-30 18:49:25 +01:00
ifArg("colors", function(bool) {
outputOptions.colors = bool;
});
API: loaderContext.depencency is more relaxed and don't need to be called before reading API: loader.seperable cannot combined with loaderContext.emitFile and loaderContext.emitSubStats loaderContext.options.resolve loaderContext.options.events loaderContext.resolve and .sync API: added profile option (and --profile) API: added workers option (and --workers) API: added closeWorkers option API: if option workers is used: options must be JSON.stringify-able. Except options.resolve and options.events. Any error thrown in loader must be an object (i. e. an Error object). Only message, stack and value of toString is passed to main process. API: The expected Cache object for options.cache has changed. API: event module is emited after the module is finished. API: event context is now named context-enum API: added event context which is emited after the context is finished. API: event dependency is removed. Use stats.dependencies for this. API: event loader is removed. Use stats.loaders for this. API: added stats.contexts as a list of contexts. API: added stats...modules[..].dependencies for as list of files which affect the module's content. API: added stats...modules[..].loaders for as list of loaders which affect the module's content. API: removed stats.modulesPerChunk, it is useless and was deprecated. API: added stats.chunkNameFiles which export the files for named chunks API: added stats.startTime, timestamp as number cmd: more colorful output to indicate caching and timing API: webpack in watch mode emits the event watch-end if watch mode have to end (i. e. loader changed). You may restart it after clearing require.cache. API: added loaderContext.loaderType as one of loader, preLoader or postLoader. API: added loaderContext.currentLoaders as list of all loader of the current type. API: added loaderContext.loaderIndex as index of current loader in loaderContext.currentLoaders. API: added loaderContext.loaders, loaderContext.preLoaders and loaderContext.postLoaders.
2012-09-25 16:45:53 +02:00
2013-01-30 18:49:25 +01:00
ifArg("sort-modules-by", function(value) {
outputOptions.modulesSort = value;
});
API: loaderContext.depencency is more relaxed and don't need to be called before reading API: loader.seperable cannot combined with loaderContext.emitFile and loaderContext.emitSubStats loaderContext.options.resolve loaderContext.options.events loaderContext.resolve and .sync API: added profile option (and --profile) API: added workers option (and --workers) API: added closeWorkers option API: if option workers is used: options must be JSON.stringify-able. Except options.resolve and options.events. Any error thrown in loader must be an object (i. e. an Error object). Only message, stack and value of toString is passed to main process. API: The expected Cache object for options.cache has changed. API: event module is emited after the module is finished. API: event context is now named context-enum API: added event context which is emited after the context is finished. API: event dependency is removed. Use stats.dependencies for this. API: event loader is removed. Use stats.loaders for this. API: added stats.contexts as a list of contexts. API: added stats...modules[..].dependencies for as list of files which affect the module's content. API: added stats...modules[..].loaders for as list of loaders which affect the module's content. API: removed stats.modulesPerChunk, it is useless and was deprecated. API: added stats.chunkNameFiles which export the files for named chunks API: added stats.startTime, timestamp as number cmd: more colorful output to indicate caching and timing API: webpack in watch mode emits the event watch-end if watch mode have to end (i. e. loader changed). You may restart it after clearing require.cache. API: added loaderContext.loaderType as one of loader, preLoader or postLoader. API: added loaderContext.currentLoaders as list of all loader of the current type. API: added loaderContext.loaderIndex as index of current loader in loaderContext.currentLoaders. API: added loaderContext.loaders, loaderContext.preLoaders and loaderContext.postLoaders.
2012-09-25 16:45:53 +02:00
2013-01-30 18:49:25 +01:00
ifArg("sort-chunks-by", function(value) {
outputOptions.chunksSort = value;
});
2012-05-12 17:30:41 +02:00
2013-01-30 18:49:25 +01:00
ifArg("sort-assets-by", function(value) {
outputOptions.assetsSort = value;
});
2012-03-10 13:11:23 +01:00
2013-02-19 11:11:43 +01:00
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;
}
2012-03-10 13:11:23 +01:00
var webpack = require("../lib/webpack.js");
2013-01-30 18:49:25 +01:00
Error.stackTrackLimit = 30;
webpack(options, function(err, stats) {
if(err) {
2013-01-30 18:49:25 +01:00
console.error(err.stack || err);
return;
}
2013-01-30 18:49:25 +01:00
if(outputOptions.json)
console.log(JSON.stringify(stats.toJson(outputOptions), null, 2));
else {
2013-01-30 18:49:25 +01:00
console.log(stats.toString(outputOptions));
}
});