UNPKG

1.5 kBJavaScriptView Raw
1var winston = require("winston");
2var omit = require("lodash/omit");
3var assign = require("lodash/assign");
4var clone = require("lodash/cloneDeep");
5var stealTools = require("../../index");
6var isString = require("lodash/isString");
7var makeStealConfig = require("./make_steal_config");
8var makeBuildOptions = require("./make_build_options");
9
10var options = assign(
11 clone(omit(require("./options"), ["bundle-steal", "watch"])),
12 {
13 minify: {
14 type: "boolean",
15 default: undefined,
16 describe: "Minify the output. Defaults to true"
17 },
18 quiet: {
19 type: "boolean",
20 describe: "Quiet output"
21 },
22 "split-loader": {
23 type: "boolean",
24 default: false,
25 describe: "Writes the optimized loader in its own bundle (loader.js)"
26 },
27 target: {
28 type: "array",
29 demandOption: false,
30 describe: [
31 "Specifies the platform where the application is going to be deployed",
32 '[choices: "web", "node", "worker"]'
33 ].join("\n")
34 }
35 }
36);
37
38module.exports = {
39 command: ["optimize"],
40
41 describe: "Creates an optimized build of a module and all of its dependencies",
42
43 builder: options,
44
45 handler: function(argv) {
46 return stealTools.optimize(makeStealConfig(argv), makeBuildOptions(argv))
47 .then(function() {
48 winston.info("\nOptimized build completed successfully".green);
49 })
50 .catch(function(e) {
51 var error = isString(e) ? new Error(e) : e;
52
53 winston.error(error.message.red);
54 winston.error("\nOptimized build failed".red);
55
56 process.exit(1);
57 });
58 }
59};