config-yargs.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. const optionsSchema = require("webpack/schemas/WebpackOptions.json");
  2. const CONFIG_GROUP = "Config options:";
  3. const BASIC_GROUP = "Basic options:";
  4. const MODULE_GROUP = "Module options:";
  5. const OUTPUT_GROUP = "Output options:";
  6. const ADVANCED_GROUP = "Advanced options:";
  7. const RESOLVE_GROUP = "Resolving options:";
  8. const OPTIMIZE_GROUP = "Optimizing options:";
  9. module.exports = function(yargs) {
  10. yargs
  11. .help("help")
  12. .alias("help", "h")
  13. .version()
  14. .alias("version", "v")
  15. .options({
  16. config: {
  17. type: "string",
  18. describe: "Path to the config file",
  19. group: CONFIG_GROUP,
  20. defaultDescription: "webpack.config.js or webpackfile.js",
  21. requiresArg: true
  22. },
  23. "config-register": {
  24. type: "array",
  25. alias: "r",
  26. describe:
  27. "Preload one or more modules before loading the webpack configuration",
  28. group: CONFIG_GROUP,
  29. defaultDescription: "module id or path",
  30. requiresArg: true
  31. },
  32. "config-name": {
  33. type: "string",
  34. describe: "Name of the config to use",
  35. group: CONFIG_GROUP,
  36. requiresArg: true
  37. },
  38. env: {
  39. describe: "Environment passed to the config, when it is a function",
  40. group: CONFIG_GROUP
  41. },
  42. mode: {
  43. type: optionsSchema.properties.mode.type,
  44. choices: optionsSchema.properties.mode.enum,
  45. describe: optionsSchema.properties.mode.description,
  46. group: CONFIG_GROUP,
  47. requiresArg: true
  48. },
  49. context: {
  50. type: optionsSchema.properties.context.type,
  51. describe: optionsSchema.properties.context.description,
  52. group: BASIC_GROUP,
  53. defaultDescription: "The current directory",
  54. requiresArg: true
  55. },
  56. entry: {
  57. type: "string",
  58. describe: optionsSchema.properties.entry.description,
  59. group: BASIC_GROUP,
  60. requiresArg: true
  61. },
  62. "module-bind": {
  63. type: "string",
  64. describe: "Bind an extension to a loader",
  65. group: MODULE_GROUP,
  66. requiresArg: true
  67. },
  68. "module-bind-post": {
  69. type: "string",
  70. describe: "Bind an extension to a post loader",
  71. group: MODULE_GROUP,
  72. requiresArg: true
  73. },
  74. "module-bind-pre": {
  75. type: "string",
  76. describe: "Bind an extension to a pre loader",
  77. group: MODULE_GROUP,
  78. requiresArg: true
  79. },
  80. output: {
  81. alias: "o",
  82. describe: "The output path and file for compilation assets",
  83. group: OUTPUT_GROUP,
  84. requiresArg: true
  85. },
  86. "output-path": {
  87. type: "string",
  88. describe: optionsSchema.definitions.output.properties.path.description,
  89. group: OUTPUT_GROUP,
  90. defaultDescription: "The current directory",
  91. requiresArg: true
  92. },
  93. "output-filename": {
  94. type: "string",
  95. describe:
  96. optionsSchema.definitions.output.properties.filename.description,
  97. group: OUTPUT_GROUP,
  98. defaultDescription: "[name].js",
  99. requiresArg: true
  100. },
  101. "output-chunk-filename": {
  102. type: "string",
  103. describe:
  104. optionsSchema.definitions.output.properties.chunkFilename.description,
  105. group: OUTPUT_GROUP,
  106. defaultDescription:
  107. "filename with [id] instead of [name] or [id] prefixed",
  108. requiresArg: true
  109. },
  110. "output-source-map-filename": {
  111. type: "string",
  112. describe:
  113. optionsSchema.definitions.output.properties.sourceMapFilename
  114. .description,
  115. group: OUTPUT_GROUP,
  116. requiresArg: true
  117. },
  118. "output-public-path": {
  119. type: "string",
  120. describe:
  121. optionsSchema.definitions.output.properties.publicPath.description,
  122. group: OUTPUT_GROUP,
  123. requiresArg: true
  124. },
  125. "output-jsonp-function": {
  126. type: "string",
  127. describe:
  128. optionsSchema.definitions.output.properties.jsonpFunction.description,
  129. group: OUTPUT_GROUP,
  130. requiresArg: true
  131. },
  132. "output-pathinfo": {
  133. type: "boolean",
  134. describe:
  135. optionsSchema.definitions.output.properties.pathinfo.description,
  136. group: OUTPUT_GROUP
  137. },
  138. "output-library": {
  139. type: "string",
  140. describe: "Expose the exports of the entry point as library",
  141. group: OUTPUT_GROUP,
  142. requiresArg: true
  143. },
  144. "output-library-target": {
  145. type: "string",
  146. describe:
  147. optionsSchema.definitions.output.properties.libraryTarget.description,
  148. choices: optionsSchema.definitions.output.properties.libraryTarget.enum,
  149. group: OUTPUT_GROUP,
  150. requiresArg: true
  151. },
  152. "records-input-path": {
  153. type: "string",
  154. describe: optionsSchema.properties.recordsInputPath.description,
  155. group: ADVANCED_GROUP,
  156. requiresArg: true
  157. },
  158. "records-output-path": {
  159. type: "string",
  160. describe: optionsSchema.properties.recordsOutputPath.description,
  161. group: ADVANCED_GROUP,
  162. requiresArg: true
  163. },
  164. "records-path": {
  165. type: "string",
  166. describe: optionsSchema.properties.recordsPath.description,
  167. group: ADVANCED_GROUP,
  168. requiresArg: true
  169. },
  170. define: {
  171. type: "string",
  172. describe: "Define any free var in the bundle",
  173. group: ADVANCED_GROUP,
  174. requiresArg: true
  175. },
  176. target: {
  177. type: "string",
  178. describe: optionsSchema.properties.target.description,
  179. group: ADVANCED_GROUP,
  180. requiresArg: true
  181. },
  182. cache: {
  183. type: "boolean",
  184. describe: optionsSchema.properties.cache.description,
  185. default: null,
  186. group: ADVANCED_GROUP,
  187. defaultDescription: "It's enabled by default when watching"
  188. },
  189. watch: {
  190. type: "boolean",
  191. alias: "w",
  192. describe: optionsSchema.properties.watch.description,
  193. group: BASIC_GROUP
  194. },
  195. "watch-stdin": {
  196. type: "boolean",
  197. alias: "stdin",
  198. describe:
  199. optionsSchema.properties.watchOptions.properties.stdin.description,
  200. group: ADVANCED_GROUP
  201. },
  202. "watch-aggregate-timeout": {
  203. describe:
  204. optionsSchema.properties.watchOptions.properties.aggregateTimeout
  205. .description,
  206. type:
  207. optionsSchema.properties.watchOptions.properties.aggregateTimeout
  208. .type,
  209. group: ADVANCED_GROUP,
  210. requiresArg: true
  211. },
  212. "watch-poll": {
  213. type: "string",
  214. describe:
  215. optionsSchema.properties.watchOptions.properties.poll.description,
  216. group: ADVANCED_GROUP
  217. },
  218. hot: {
  219. type: "boolean",
  220. describe: "Enables Hot Module Replacement",
  221. group: ADVANCED_GROUP
  222. },
  223. debug: {
  224. type: "boolean",
  225. describe: "Switch loaders to debug mode",
  226. group: BASIC_GROUP
  227. },
  228. devtool: {
  229. type: "string",
  230. describe: optionsSchema.properties.devtool.description,
  231. group: BASIC_GROUP,
  232. requiresArg: true
  233. },
  234. "resolve-alias": {
  235. type: "string",
  236. describe:
  237. optionsSchema.definitions.resolve.properties.alias.description,
  238. group: RESOLVE_GROUP,
  239. requiresArg: true
  240. },
  241. "resolve-extensions": {
  242. type: "array",
  243. describe:
  244. optionsSchema.definitions.resolve.properties.alias.description,
  245. group: RESOLVE_GROUP,
  246. requiresArg: true
  247. },
  248. "resolve-loader-alias": {
  249. type: "string",
  250. describe: "Setup a loader alias for resolving",
  251. group: RESOLVE_GROUP,
  252. requiresArg: true
  253. },
  254. "optimize-max-chunks": {
  255. describe: "Try to keep the chunk count below a limit",
  256. group: OPTIMIZE_GROUP,
  257. requiresArg: true
  258. },
  259. "optimize-min-chunk-size": {
  260. describe:
  261. optionsSchema.properties.optimization.properties.splitChunks.oneOf[1]
  262. .properties.minSize.description,
  263. group: OPTIMIZE_GROUP,
  264. requiresArg: true
  265. },
  266. "optimize-minimize": {
  267. type: "boolean",
  268. describe:
  269. optionsSchema.properties.optimization.properties.minimize.description,
  270. group: OPTIMIZE_GROUP
  271. },
  272. prefetch: {
  273. type: "string",
  274. describe: "Prefetch this request (Example: --prefetch ./file.js)",
  275. group: ADVANCED_GROUP,
  276. requiresArg: true
  277. },
  278. provide: {
  279. type: "string",
  280. describe:
  281. "Provide these modules as free vars in all modules (Example: --provide jQuery=jquery)",
  282. group: ADVANCED_GROUP,
  283. requiresArg: true
  284. },
  285. "labeled-modules": {
  286. type: "boolean",
  287. describe: "Enables labeled modules",
  288. group: ADVANCED_GROUP
  289. },
  290. plugin: {
  291. type: "string",
  292. describe: "Load this plugin",
  293. group: ADVANCED_GROUP,
  294. requiresArg: true
  295. },
  296. bail: {
  297. type: optionsSchema.properties.bail.type,
  298. describe: optionsSchema.properties.bail.description,
  299. group: ADVANCED_GROUP,
  300. default: null
  301. },
  302. profile: {
  303. type: "boolean",
  304. describe: optionsSchema.properties.profile.description,
  305. group: ADVANCED_GROUP,
  306. default: null
  307. },
  308. d: {
  309. type: "boolean",
  310. describe:
  311. "shortcut for --debug --devtool eval-cheap-module-source-map --output-pathinfo",
  312. group: BASIC_GROUP
  313. },
  314. p: {
  315. type: "boolean",
  316. describe:
  317. "shortcut for --optimize-minimize --define process.env.NODE_ENV=\"production\"",
  318. group: BASIC_GROUP
  319. }
  320. });
  321. };