UNPKG

2.29 kBJavaScriptView Raw
1const { basename, dirname, isAbsolute, resolve } = require('path');
2
3const camelcase = require('camelcase');
4const merge = require('merge-options');
5
6module.exports = {
7 apply(argv, options) {
8 const output = {};
9 const { flags } = module.exports;
10 const keys = Object.keys(flags).filter((key) => key !== 'output');
11
12 if (argv.output) {
13 let outputPath = argv.output;
14 if (!isAbsolute(outputPath)) {
15 outputPath = resolve(process.cwd(), outputPath);
16 }
17 argv.outputFilename = basename(outputPath); // eslint-disable-line no-param-reassign
18 argv.outputPath = dirname(outputPath); // eslint-disable-line no-param-reassign
19 }
20
21 for (const key of keys) {
22 const arg = camelcase(key);
23 let value = argv[arg];
24
25 if (value) {
26 if (arg === 'outputPath') {
27 value = resolve(value);
28 }
29
30 if (typeof value !== 'undefined') {
31 output[camelcase(key.replace('output-', ''))] = value;
32 }
33 }
34 }
35
36 return merge(options, { output });
37 },
38
39 flags: {
40 output: {
41 alias: 'o',
42 desc: 'The output path and file for compilation assets',
43 type: 'string',
44 },
45 'output-chunk-filename': {
46 desc: 'The output filename for additional chunks',
47 type: 'string',
48 },
49 'output-filename': {
50 desc: 'The output filename of the bundle',
51 type: 'string',
52 },
53 'output-jsonp-function': {
54 desc: 'The name of the JSONP function used for chunk loading',
55 type: 'string',
56 },
57 'output-library': {
58 desc: 'Expose the exports of the entry point as library',
59 type: 'string',
60 },
61 'output-library-target': {
62 desc: 'The type for exposing the exports of the entry point as library',
63 type: 'string',
64 },
65 'output-path': {
66 desc: 'The output path for compilation assets',
67 type: 'string',
68 },
69 'output-pathinfo': {
70 desc:
71 'Include a comment with the request for every dependency (require, import, etc.)',
72 type: 'boolean',
73 },
74 'output-public-path': {
75 desc: 'The public path for the assets',
76 type: 'string',
77 },
78 'output-source-map-filename': {
79 desc: 'The output filename for the SourceMap',
80 type: 'string',
81 },
82 },
83
84 name: 'Output',
85};