var appPath = process.argv[2] || process.cwd(); var buildPath = process.argv[3] || process.cwd() + '/build.json'; var webpackPath = process.argv[4] || process.cwd() + '/node_modules/webpack'; var webpack = require(webpackPath); try { var entries = require(buildPath); } catch (e) { var entries = {main:{}}; } var config = Object.keys(entries).map(function(entry) { delete require.cache[require.resolve(appPath)]; var child = require(appPath).builder; child.name = entry; var main = child.entry.main; delete child.entry.main; child.entry[entry] = main; child.plugins.push(new webpack.DefinePlugin(encode(entries[entry]))); return child; }); function encode(obj) { for (k in obj) { obj[k] = JSON.stringify(obj[k]); } return obj; } function handleFatalError(err) { console.error(err.stack); process.exit(1); } function handleSoftErrors(errors) { errors.forEach(function(err) { console.error(err.stack || err); }); process.exit(1); } webpack(config, function(err, stats) { if (err) return handleFatalError(err); var jsonStats = stats.toJson(); if (jsonStats.errors.length > 0) return handleSoftErrors(jsonStats.errors); console.log(stats.toString({ "cached": false, "cachedAssets": false, "modules": true, "chunks": false, "reasons": false, "errorDetails": false, "chunkOrigins": false, "exclude": [ "node_modules", "bower_components", "jam", "components" ] })); process.exit(0); });