defaults.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const fs = require("fs");
  7. const path = require("path");
  8. const Template = require("../Template");
  9. const { cleverMerge } = require("../util/cleverMerge");
  10. const {
  11. getTargetsProperties,
  12. getTargetProperties,
  13. getDefaultTarget
  14. } = require("./target");
  15. /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
  16. /** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
  17. /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
  18. /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
  19. /** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
  20. /** @typedef {import("../../declarations/WebpackOptions").ExperimentsNormalized} ExperimentsNormalized */
  21. /** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
  22. /** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
  23. /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
  24. /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
  25. /** @typedef {import("../../declarations/WebpackOptions").Library} Library */
  26. /** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
  27. /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
  28. /** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */
  29. /** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */
  30. /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
  31. /** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
  32. /** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
  33. /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
  34. /** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
  35. /** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
  36. /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
  37. /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
  38. /** @typedef {import("../../declarations/WebpackOptions").Target} Target */
  39. /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
  40. /** @typedef {import("./target").TargetProperties} TargetProperties */
  41. const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
  42. /**
  43. * Sets a constant default value when undefined
  44. * @template T
  45. * @template {keyof T} P
  46. * @param {T} obj an object
  47. * @param {P} prop a property of this object
  48. * @param {T[P]} value a default value of the property
  49. * @returns {void}
  50. */
  51. const D = (obj, prop, value) => {
  52. if (obj[prop] === undefined) {
  53. obj[prop] = value;
  54. }
  55. };
  56. /**
  57. * Sets a dynamic default value when undefined, by calling the factory function
  58. * @template T
  59. * @template {keyof T} P
  60. * @param {T} obj an object
  61. * @param {P} prop a property of this object
  62. * @param {function(): T[P]} factory a default value factory for the property
  63. * @returns {void}
  64. */
  65. const F = (obj, prop, factory) => {
  66. if (obj[prop] === undefined) {
  67. obj[prop] = factory();
  68. }
  69. };
  70. /**
  71. * Sets a dynamic default value when undefined, by calling the factory function.
  72. * factory must return an array or undefined
  73. * When the current value is already an array an contains "..." it's replaced with
  74. * the result of the factory function
  75. * @template T
  76. * @template {keyof T} P
  77. * @param {T} obj an object
  78. * @param {P} prop a property of this object
  79. * @param {function(): T[P]} factory a default value factory for the property
  80. * @returns {void}
  81. */
  82. const A = (obj, prop, factory) => {
  83. const value = obj[prop];
  84. if (value === undefined) {
  85. obj[prop] = factory();
  86. } else if (Array.isArray(value)) {
  87. /** @type {any[]} */
  88. let newArray = undefined;
  89. for (let i = 0; i < value.length; i++) {
  90. const item = value[i];
  91. if (item === "...") {
  92. if (newArray === undefined) {
  93. newArray = value.slice(0, i);
  94. obj[prop] = /** @type {T[P]} */ (/** @type {unknown} */ (newArray));
  95. }
  96. const items = /** @type {any[]} */ (/** @type {unknown} */ (factory()));
  97. if (items !== undefined) {
  98. for (const item of items) {
  99. newArray.push(item);
  100. }
  101. }
  102. } else if (newArray !== undefined) {
  103. newArray.push(item);
  104. }
  105. }
  106. }
  107. };
  108. /**
  109. * @param {WebpackOptions} options options to be modified
  110. * @returns {void}
  111. */
  112. const applyWebpackOptionsBaseDefaults = options => {
  113. F(options, "context", () => process.cwd());
  114. applyInfrastructureLoggingDefaults(options.infrastructureLogging);
  115. };
  116. /**
  117. * @param {WebpackOptions} options options to be modified
  118. * @returns {void}
  119. */
  120. const applyWebpackOptionsDefaults = options => {
  121. F(options, "context", () => process.cwd());
  122. F(options, "target", () => {
  123. return getDefaultTarget(options.context);
  124. });
  125. const { mode, name, target } = options;
  126. let targetProperties =
  127. target === false
  128. ? /** @type {false} */ (false)
  129. : typeof target === "string"
  130. ? getTargetProperties(target, options.context)
  131. : getTargetsProperties(target, options.context);
  132. const development = mode === "development";
  133. const production = mode === "production" || !mode;
  134. if (typeof options.entry !== "function") {
  135. for (const key of Object.keys(options.entry)) {
  136. F(
  137. options.entry[key],
  138. "import",
  139. () => /** @type {[string]} */ (["./src"])
  140. );
  141. }
  142. }
  143. F(options, "devtool", () => (development ? "eval" : false));
  144. D(options, "watch", false);
  145. D(options, "profile", false);
  146. D(options, "parallelism", 100);
  147. D(options, "recordsInputPath", false);
  148. D(options, "recordsOutputPath", false);
  149. applyExperimentsDefaults(options.experiments, {
  150. production,
  151. development,
  152. targetProperties
  153. });
  154. const futureDefaults = options.experiments.futureDefaults;
  155. F(options, "cache", () =>
  156. development ? { type: /** @type {"memory"} */ ("memory") } : false
  157. );
  158. applyCacheDefaults(options.cache, {
  159. name: name || "default",
  160. mode: mode || "production",
  161. development,
  162. cacheUnaffected: options.experiments.cacheUnaffected
  163. });
  164. const cache = !!options.cache;
  165. applySnapshotDefaults(options.snapshot, {
  166. production,
  167. futureDefaults
  168. });
  169. applyModuleDefaults(options.module, {
  170. cache,
  171. syncWebAssembly: options.experiments.syncWebAssembly,
  172. asyncWebAssembly: options.experiments.asyncWebAssembly,
  173. css: options.experiments.css,
  174. futureDefaults
  175. });
  176. applyOutputDefaults(options.output, {
  177. context: options.context,
  178. targetProperties,
  179. isAffectedByBrowserslist:
  180. target === undefined ||
  181. (typeof target === "string" && target.startsWith("browserslist")) ||
  182. (Array.isArray(target) &&
  183. target.some(target => target.startsWith("browserslist"))),
  184. outputModule: options.experiments.outputModule,
  185. development,
  186. entry: options.entry,
  187. module: options.module,
  188. futureDefaults
  189. });
  190. applyExternalsPresetsDefaults(options.externalsPresets, {
  191. targetProperties,
  192. buildHttp: !!options.experiments.buildHttp
  193. });
  194. applyLoaderDefaults(options.loader, { targetProperties });
  195. F(options, "externalsType", () => {
  196. const validExternalTypes = require("../../schemas/WebpackOptions.json")
  197. .definitions.ExternalsType.enum;
  198. return options.output.library &&
  199. validExternalTypes.includes(options.output.library.type)
  200. ? /** @type {ExternalsType} */ (options.output.library.type)
  201. : options.output.module
  202. ? "module"
  203. : "var";
  204. });
  205. applyNodeDefaults(options.node, {
  206. futureDefaults: options.experiments.futureDefaults,
  207. targetProperties
  208. });
  209. F(options, "performance", () =>
  210. production &&
  211. targetProperties &&
  212. (targetProperties.browser || targetProperties.browser === null)
  213. ? {}
  214. : false
  215. );
  216. applyPerformanceDefaults(options.performance, {
  217. production
  218. });
  219. applyOptimizationDefaults(options.optimization, {
  220. development,
  221. production,
  222. css: options.experiments.css,
  223. records: !!(options.recordsInputPath || options.recordsOutputPath)
  224. });
  225. options.resolve = cleverMerge(
  226. getResolveDefaults({
  227. cache,
  228. context: options.context,
  229. targetProperties,
  230. mode: options.mode
  231. }),
  232. options.resolve
  233. );
  234. options.resolveLoader = cleverMerge(
  235. getResolveLoaderDefaults({ cache }),
  236. options.resolveLoader
  237. );
  238. };
  239. /**
  240. * @param {ExperimentsNormalized} experiments options
  241. * @param {Object} options options
  242. * @param {boolean} options.production is production
  243. * @param {boolean} options.development is development mode
  244. * @param {TargetProperties | false} options.targetProperties target properties
  245. * @returns {void}
  246. */
  247. const applyExperimentsDefaults = (
  248. experiments,
  249. { production, development, targetProperties }
  250. ) => {
  251. D(experiments, "futureDefaults", false);
  252. D(experiments, "backCompat", !experiments.futureDefaults);
  253. D(experiments, "topLevelAwait", experiments.futureDefaults);
  254. D(experiments, "syncWebAssembly", false);
  255. D(experiments, "asyncWebAssembly", experiments.futureDefaults);
  256. D(experiments, "outputModule", false);
  257. D(experiments, "layers", false);
  258. D(experiments, "lazyCompilation", undefined);
  259. D(experiments, "buildHttp", undefined);
  260. D(experiments, "cacheUnaffected", experiments.futureDefaults);
  261. F(experiments, "css", () => (experiments.futureDefaults ? {} : undefined));
  262. if (typeof experiments.buildHttp === "object") {
  263. D(experiments.buildHttp, "frozen", production);
  264. D(experiments.buildHttp, "upgrade", false);
  265. }
  266. if (typeof experiments.css === "object") {
  267. D(
  268. experiments.css,
  269. "exportsOnly",
  270. !targetProperties || !targetProperties.document
  271. );
  272. }
  273. };
  274. /**
  275. * @param {CacheOptions} cache options
  276. * @param {Object} options options
  277. * @param {string} options.name name
  278. * @param {string} options.mode mode
  279. * @param {boolean} options.development is development mode
  280. * @param {boolean} options.cacheUnaffected the cacheUnaffected experiment is enabled
  281. * @returns {void}
  282. */
  283. const applyCacheDefaults = (
  284. cache,
  285. { name, mode, development, cacheUnaffected }
  286. ) => {
  287. if (cache === false) return;
  288. switch (cache.type) {
  289. case "filesystem":
  290. F(cache, "name", () => name + "-" + mode);
  291. D(cache, "version", "");
  292. F(cache, "cacheDirectory", () => {
  293. const cwd = process.cwd();
  294. let dir = cwd;
  295. for (;;) {
  296. try {
  297. if (fs.statSync(path.join(dir, "package.json")).isFile()) break;
  298. // eslint-disable-next-line no-empty
  299. } catch (e) {}
  300. const parent = path.dirname(dir);
  301. if (dir === parent) {
  302. dir = undefined;
  303. break;
  304. }
  305. dir = parent;
  306. }
  307. if (!dir) {
  308. return path.resolve(cwd, ".cache/webpack");
  309. } else if (process.versions.pnp === "1") {
  310. return path.resolve(dir, ".pnp/.cache/webpack");
  311. } else if (process.versions.pnp === "3") {
  312. return path.resolve(dir, ".yarn/.cache/webpack");
  313. } else {
  314. return path.resolve(dir, "node_modules/.cache/webpack");
  315. }
  316. });
  317. F(cache, "cacheLocation", () =>
  318. path.resolve(cache.cacheDirectory, cache.name)
  319. );
  320. D(cache, "hashAlgorithm", "md4");
  321. D(cache, "store", "pack");
  322. D(cache, "compression", false);
  323. D(cache, "profile", false);
  324. D(cache, "idleTimeout", 60000);
  325. D(cache, "idleTimeoutForInitialStore", 5000);
  326. D(cache, "idleTimeoutAfterLargeChanges", 1000);
  327. D(cache, "maxMemoryGenerations", development ? 5 : Infinity);
  328. D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
  329. D(cache, "allowCollectingMemory", development);
  330. D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
  331. D(cache.buildDependencies, "defaultWebpack", [
  332. path.resolve(__dirname, "..") + path.sep
  333. ]);
  334. break;
  335. case "memory":
  336. D(cache, "maxGenerations", Infinity);
  337. D(cache, "cacheUnaffected", development && cacheUnaffected);
  338. break;
  339. }
  340. };
  341. /**
  342. * @param {SnapshotOptions} snapshot options
  343. * @param {Object} options options
  344. * @param {boolean} options.production is production
  345. * @param {boolean} options.futureDefaults is future defaults enabled
  346. * @returns {void}
  347. */
  348. const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
  349. if (futureDefaults) {
  350. F(snapshot, "managedPaths", () =>
  351. process.versions.pnp === "3"
  352. ? [
  353. /^(.+?(?:[\\/]\.yarn[\\/]unplugged[\\/][^\\/]+)?[\\/]node_modules[\\/])/
  354. ]
  355. : [/^(.+?[\\/]node_modules[\\/])/]
  356. );
  357. F(snapshot, "immutablePaths", () =>
  358. process.versions.pnp === "3"
  359. ? [/^(.+?[\\/]cache[\\/][^\\/]+\.zip[\\/]node_modules[\\/])/]
  360. : []
  361. );
  362. } else {
  363. A(snapshot, "managedPaths", () => {
  364. if (process.versions.pnp === "3") {
  365. const match =
  366. /^(.+?)[\\/]cache[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
  367. require.resolve("watchpack")
  368. );
  369. if (match) {
  370. return [path.resolve(match[1], "unplugged")];
  371. }
  372. } else {
  373. const match = /^(.+?[\\/]node_modules[\\/])/.exec(
  374. // eslint-disable-next-line node/no-extraneous-require
  375. require.resolve("watchpack")
  376. );
  377. if (match) {
  378. return [match[1]];
  379. }
  380. }
  381. return [];
  382. });
  383. A(snapshot, "immutablePaths", () => {
  384. if (process.versions.pnp === "1") {
  385. const match =
  386. /^(.+?[\\/]v4)[\\/]npm-watchpack-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
  387. require.resolve("watchpack")
  388. );
  389. if (match) {
  390. return [match[1]];
  391. }
  392. } else if (process.versions.pnp === "3") {
  393. const match =
  394. /^(.+?)[\\/]watchpack-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
  395. require.resolve("watchpack")
  396. );
  397. if (match) {
  398. return [match[1]];
  399. }
  400. }
  401. return [];
  402. });
  403. }
  404. F(snapshot, "resolveBuildDependencies", () => ({
  405. timestamp: true,
  406. hash: true
  407. }));
  408. F(snapshot, "buildDependencies", () => ({ timestamp: true, hash: true }));
  409. F(snapshot, "module", () =>
  410. production ? { timestamp: true, hash: true } : { timestamp: true }
  411. );
  412. F(snapshot, "resolve", () =>
  413. production ? { timestamp: true, hash: true } : { timestamp: true }
  414. );
  415. };
  416. /**
  417. * @param {JavascriptParserOptions} parserOptions parser options
  418. * @param {Object} options options
  419. * @param {boolean} options.futureDefaults is future defaults enabled
  420. * @returns {void}
  421. */
  422. const applyJavascriptParserOptionsDefaults = (
  423. parserOptions,
  424. { futureDefaults }
  425. ) => {
  426. D(parserOptions, "unknownContextRequest", ".");
  427. D(parserOptions, "unknownContextRegExp", false);
  428. D(parserOptions, "unknownContextRecursive", true);
  429. D(parserOptions, "unknownContextCritical", true);
  430. D(parserOptions, "exprContextRequest", ".");
  431. D(parserOptions, "exprContextRegExp", false);
  432. D(parserOptions, "exprContextRecursive", true);
  433. D(parserOptions, "exprContextCritical", true);
  434. D(parserOptions, "wrappedContextRegExp", /.*/);
  435. D(parserOptions, "wrappedContextRecursive", true);
  436. D(parserOptions, "wrappedContextCritical", false);
  437. D(parserOptions, "strictThisContextOnImports", false);
  438. D(parserOptions, "importMeta", true);
  439. if (futureDefaults) D(parserOptions, "exportsPresence", "error");
  440. };
  441. /**
  442. * @param {ModuleOptions} module options
  443. * @param {Object} options options
  444. * @param {boolean} options.cache is caching enabled
  445. * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
  446. * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
  447. * @param {CssExperimentOptions} options.css is css enabled
  448. * @param {boolean} options.futureDefaults is future defaults enabled
  449. * @returns {void}
  450. */
  451. const applyModuleDefaults = (
  452. module,
  453. { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults }
  454. ) => {
  455. if (cache) {
  456. D(module, "unsafeCache", module => {
  457. const name = module.nameForCondition();
  458. return name && NODE_MODULES_REGEXP.test(name);
  459. });
  460. } else {
  461. D(module, "unsafeCache", false);
  462. }
  463. F(module.parser, "asset", () => ({}));
  464. F(module.parser.asset, "dataUrlCondition", () => ({}));
  465. if (typeof module.parser.asset.dataUrlCondition === "object") {
  466. D(module.parser.asset.dataUrlCondition, "maxSize", 8096);
  467. }
  468. F(module.parser, "javascript", () => ({}));
  469. applyJavascriptParserOptionsDefaults(module.parser.javascript, {
  470. futureDefaults
  471. });
  472. A(module, "defaultRules", () => {
  473. const esm = {
  474. type: "javascript/esm",
  475. resolve: {
  476. byDependency: {
  477. esm: {
  478. fullySpecified: true
  479. }
  480. }
  481. }
  482. };
  483. const commonjs = {
  484. type: "javascript/dynamic"
  485. };
  486. /** @type {RuleSetRules} */
  487. const rules = [
  488. {
  489. mimetype: "application/node",
  490. type: "javascript/auto"
  491. },
  492. {
  493. test: /\.json$/i,
  494. type: "json"
  495. },
  496. {
  497. mimetype: "application/json",
  498. type: "json"
  499. },
  500. {
  501. test: /\.mjs$/i,
  502. ...esm
  503. },
  504. {
  505. test: /\.js$/i,
  506. descriptionData: {
  507. type: "module"
  508. },
  509. ...esm
  510. },
  511. {
  512. test: /\.cjs$/i,
  513. ...commonjs
  514. },
  515. {
  516. test: /\.js$/i,
  517. descriptionData: {
  518. type: "commonjs"
  519. },
  520. ...commonjs
  521. },
  522. {
  523. mimetype: {
  524. or: ["text/javascript", "application/javascript"]
  525. },
  526. ...esm
  527. }
  528. ];
  529. if (asyncWebAssembly) {
  530. const wasm = {
  531. type: "webassembly/async",
  532. rules: [
  533. {
  534. descriptionData: {
  535. type: "module"
  536. },
  537. resolve: {
  538. fullySpecified: true
  539. }
  540. }
  541. ]
  542. };
  543. rules.push({
  544. test: /\.wasm$/i,
  545. ...wasm
  546. });
  547. rules.push({
  548. mimetype: "application/wasm",
  549. ...wasm
  550. });
  551. } else if (syncWebAssembly) {
  552. const wasm = {
  553. type: "webassembly/sync",
  554. rules: [
  555. {
  556. descriptionData: {
  557. type: "module"
  558. },
  559. resolve: {
  560. fullySpecified: true
  561. }
  562. }
  563. ]
  564. };
  565. rules.push({
  566. test: /\.wasm$/i,
  567. ...wasm
  568. });
  569. rules.push({
  570. mimetype: "application/wasm",
  571. ...wasm
  572. });
  573. }
  574. if (css) {
  575. const cssRule = {
  576. type: "css",
  577. resolve: {
  578. fullySpecified: true,
  579. preferRelative: true
  580. }
  581. };
  582. const cssModulesRule = {
  583. type: "css/module",
  584. resolve: {
  585. fullySpecified: true
  586. }
  587. };
  588. rules.push({
  589. test: /\.css$/i,
  590. oneOf: [
  591. {
  592. test: /\.module\.css$/i,
  593. ...cssModulesRule
  594. },
  595. {
  596. ...cssRule
  597. }
  598. ]
  599. });
  600. rules.push({
  601. mimetype: "text/css+module",
  602. ...cssModulesRule
  603. });
  604. rules.push({
  605. mimetype: "text/css",
  606. ...cssRule
  607. });
  608. }
  609. rules.push(
  610. {
  611. dependency: "url",
  612. oneOf: [
  613. {
  614. scheme: /^data$/,
  615. type: "asset/inline"
  616. },
  617. {
  618. type: "asset/resource"
  619. }
  620. ]
  621. },
  622. {
  623. assert: { type: "json" },
  624. type: "json"
  625. }
  626. );
  627. return rules;
  628. });
  629. };
  630. /**
  631. * @param {Output} output options
  632. * @param {Object} options options
  633. * @param {string} options.context context
  634. * @param {TargetProperties | false} options.targetProperties target properties
  635. * @param {boolean} options.isAffectedByBrowserslist is affected by browserslist
  636. * @param {boolean} options.outputModule is outputModule experiment enabled
  637. * @param {boolean} options.development is development mode
  638. * @param {Entry} options.entry entry option
  639. * @param {ModuleOptions} options.module module option
  640. * @param {boolean} options.futureDefaults is future defaults enabled
  641. * @returns {void}
  642. */
  643. const applyOutputDefaults = (
  644. output,
  645. {
  646. context,
  647. targetProperties: tp,
  648. isAffectedByBrowserslist,
  649. outputModule,
  650. development,
  651. entry,
  652. module,
  653. futureDefaults
  654. }
  655. ) => {
  656. /**
  657. * @param {Library=} library the library option
  658. * @returns {string} a readable library name
  659. */
  660. const getLibraryName = library => {
  661. const libraryName =
  662. typeof library === "object" &&
  663. library &&
  664. !Array.isArray(library) &&
  665. "type" in library
  666. ? library.name
  667. : /** @type {LibraryName=} */ (library);
  668. if (Array.isArray(libraryName)) {
  669. return libraryName.join(".");
  670. } else if (typeof libraryName === "object") {
  671. return getLibraryName(libraryName.root);
  672. } else if (typeof libraryName === "string") {
  673. return libraryName;
  674. }
  675. return "";
  676. };
  677. F(output, "uniqueName", () => {
  678. const libraryName = getLibraryName(output.library);
  679. if (libraryName) return libraryName;
  680. const pkgPath = path.resolve(context, "package.json");
  681. try {
  682. const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
  683. return packageInfo.name || "";
  684. } catch (e) {
  685. if (e.code !== "ENOENT") {
  686. e.message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
  687. throw e;
  688. }
  689. return "";
  690. }
  691. });
  692. F(output, "module", () => !!outputModule);
  693. D(output, "filename", output.module ? "[name].mjs" : "[name].js");
  694. F(output, "iife", () => !output.module);
  695. D(output, "importFunctionName", "import");
  696. D(output, "importMetaName", "import.meta");
  697. F(output, "chunkFilename", () => {
  698. const filename = output.filename;
  699. if (typeof filename !== "function") {
  700. const hasName = filename.includes("[name]");
  701. const hasId = filename.includes("[id]");
  702. const hasChunkHash = filename.includes("[chunkhash]");
  703. const hasContentHash = filename.includes("[contenthash]");
  704. // Anything changing depending on chunk is fine
  705. if (hasChunkHash || hasContentHash || hasName || hasId) return filename;
  706. // Otherwise prefix "[id]." in front of the basename to make it changing
  707. return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
  708. }
  709. return output.module ? "[id].mjs" : "[id].js";
  710. });
  711. F(output, "cssFilename", () => {
  712. const filename = output.filename;
  713. if (typeof filename !== "function") {
  714. return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
  715. }
  716. return "[id].css";
  717. });
  718. F(output, "cssChunkFilename", () => {
  719. const chunkFilename = output.chunkFilename;
  720. if (typeof chunkFilename !== "function") {
  721. return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
  722. }
  723. return "[id].css";
  724. });
  725. D(output, "assetModuleFilename", "[hash][ext][query]");
  726. D(output, "webassemblyModuleFilename", "[hash].module.wasm");
  727. D(output, "compareBeforeEmit", true);
  728. D(output, "charset", true);
  729. F(output, "hotUpdateGlobal", () =>
  730. Template.toIdentifier(
  731. "webpackHotUpdate" + Template.toIdentifier(output.uniqueName)
  732. )
  733. );
  734. F(output, "chunkLoadingGlobal", () =>
  735. Template.toIdentifier(
  736. "webpackChunk" + Template.toIdentifier(output.uniqueName)
  737. )
  738. );
  739. F(output, "globalObject", () => {
  740. if (tp) {
  741. if (tp.global) return "global";
  742. if (tp.globalThis) return "globalThis";
  743. }
  744. return "self";
  745. });
  746. F(output, "chunkFormat", () => {
  747. if (tp) {
  748. const helpMessage = isAffectedByBrowserslist
  749. ? "Make sure that your 'browserslist' includes only platforms that support these features or select an appropriate 'target' to allow selecting a chunk format by default. Alternatively specify the 'output.chunkFormat' directly."
  750. : "Select an appropriate 'target' to allow selecting one by default, or specify the 'output.chunkFormat' directly.";
  751. if (output.module) {
  752. if (tp.dynamicImport) return "module";
  753. if (tp.document) return "array-push";
  754. throw new Error(
  755. "For the selected environment is no default ESM chunk format available:\n" +
  756. "ESM exports can be chosen when 'import()' is available.\n" +
  757. "JSONP Array push can be chosen when 'document' is available.\n" +
  758. helpMessage
  759. );
  760. } else {
  761. if (tp.document) return "array-push";
  762. if (tp.require) return "commonjs";
  763. if (tp.nodeBuiltins) return "commonjs";
  764. if (tp.importScripts) return "array-push";
  765. throw new Error(
  766. "For the selected environment is no default script chunk format available:\n" +
  767. "JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
  768. "CommonJs exports can be chosen when 'require' or node builtins are available.\n" +
  769. helpMessage
  770. );
  771. }
  772. }
  773. throw new Error(
  774. "Chunk format can't be selected by default when no target is specified"
  775. );
  776. });
  777. D(output, "asyncChunks", true);
  778. F(output, "chunkLoading", () => {
  779. if (tp) {
  780. switch (output.chunkFormat) {
  781. case "array-push":
  782. if (tp.document) return "jsonp";
  783. if (tp.importScripts) return "import-scripts";
  784. break;
  785. case "commonjs":
  786. if (tp.require) return "require";
  787. if (tp.nodeBuiltins) return "async-node";
  788. break;
  789. case "module":
  790. if (tp.dynamicImport) return "import";
  791. break;
  792. }
  793. if (
  794. tp.require === null ||
  795. tp.nodeBuiltins === null ||
  796. tp.document === null ||
  797. tp.importScripts === null
  798. ) {
  799. return "universal";
  800. }
  801. }
  802. return false;
  803. });
  804. F(output, "workerChunkLoading", () => {
  805. if (tp) {
  806. switch (output.chunkFormat) {
  807. case "array-push":
  808. if (tp.importScriptsInWorker) return "import-scripts";
  809. break;
  810. case "commonjs":
  811. if (tp.require) return "require";
  812. if (tp.nodeBuiltins) return "async-node";
  813. break;
  814. case "module":
  815. if (tp.dynamicImportInWorker) return "import";
  816. break;
  817. }
  818. if (
  819. tp.require === null ||
  820. tp.nodeBuiltins === null ||
  821. tp.importScriptsInWorker === null
  822. ) {
  823. return "universal";
  824. }
  825. }
  826. return false;
  827. });
  828. F(output, "wasmLoading", () => {
  829. if (tp) {
  830. if (tp.fetchWasm) return "fetch";
  831. if (tp.nodeBuiltins)
  832. return output.module ? "async-node-module" : "async-node";
  833. if (tp.nodeBuiltins === null || tp.fetchWasm === null) {
  834. return "universal";
  835. }
  836. }
  837. return false;
  838. });
  839. F(output, "workerWasmLoading", () => output.wasmLoading);
  840. F(output, "devtoolNamespace", () => output.uniqueName);
  841. if (output.library) {
  842. F(output.library, "type", () => (output.module ? "module" : "var"));
  843. }
  844. F(output, "path", () => path.join(process.cwd(), "dist"));
  845. F(output, "pathinfo", () => development);
  846. D(output, "sourceMapFilename", "[file].map[query]");
  847. D(
  848. output,
  849. "hotUpdateChunkFilename",
  850. `[id].[fullhash].hot-update.${output.module ? "mjs" : "js"}`
  851. );
  852. D(output, "hotUpdateMainFilename", "[runtime].[fullhash].hot-update.json");
  853. D(output, "crossOriginLoading", false);
  854. F(output, "scriptType", () => (output.module ? "module" : false));
  855. D(
  856. output,
  857. "publicPath",
  858. (tp && (tp.document || tp.importScripts)) || output.scriptType === "module"
  859. ? "auto"
  860. : ""
  861. );
  862. D(output, "chunkLoadTimeout", 120000);
  863. D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
  864. D(output, "hashDigest", "hex");
  865. D(output, "hashDigestLength", futureDefaults ? 16 : 20);
  866. D(output, "strictModuleExceptionHandling", false);
  867. const optimistic = v => v || v === undefined;
  868. const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
  869. F(
  870. output.environment,
  871. "arrowFunction",
  872. () => tp && optimistic(tp.arrowFunction)
  873. );
  874. F(output.environment, "const", () => tp && optimistic(tp.const));
  875. F(
  876. output.environment,
  877. "destructuring",
  878. () => tp && optimistic(tp.destructuring)
  879. );
  880. F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
  881. F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
  882. F(output.environment, "dynamicImport", () =>
  883. conditionallyOptimistic(tp && tp.dynamicImport, output.module)
  884. );
  885. F(output.environment, "module", () =>
  886. conditionallyOptimistic(tp && tp.module, output.module)
  887. );
  888. const { trustedTypes } = output;
  889. if (trustedTypes) {
  890. F(
  891. trustedTypes,
  892. "policyName",
  893. () =>
  894. output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
  895. );
  896. }
  897. /**
  898. * @param {function(EntryDescription): void} fn iterator
  899. * @returns {void}
  900. */
  901. const forEachEntry = fn => {
  902. for (const name of Object.keys(entry)) {
  903. fn(entry[name]);
  904. }
  905. };
  906. A(output, "enabledLibraryTypes", () => {
  907. const enabledLibraryTypes = [];
  908. if (output.library) {
  909. enabledLibraryTypes.push(output.library.type);
  910. }
  911. forEachEntry(desc => {
  912. if (desc.library) {
  913. enabledLibraryTypes.push(desc.library.type);
  914. }
  915. });
  916. return enabledLibraryTypes;
  917. });
  918. A(output, "enabledChunkLoadingTypes", () => {
  919. const enabledChunkLoadingTypes = new Set();
  920. if (output.chunkLoading) {
  921. enabledChunkLoadingTypes.add(output.chunkLoading);
  922. }
  923. if (output.workerChunkLoading) {
  924. enabledChunkLoadingTypes.add(output.workerChunkLoading);
  925. }
  926. forEachEntry(desc => {
  927. if (desc.chunkLoading) {
  928. enabledChunkLoadingTypes.add(desc.chunkLoading);
  929. }
  930. });
  931. return Array.from(enabledChunkLoadingTypes);
  932. });
  933. A(output, "enabledWasmLoadingTypes", () => {
  934. const enabledWasmLoadingTypes = new Set();
  935. if (output.wasmLoading) {
  936. enabledWasmLoadingTypes.add(output.wasmLoading);
  937. }
  938. if (output.workerWasmLoading) {
  939. enabledWasmLoadingTypes.add(output.workerWasmLoading);
  940. }
  941. forEachEntry(desc => {
  942. if (desc.wasmLoading) {
  943. enabledWasmLoadingTypes.add(desc.wasmLoading);
  944. }
  945. });
  946. return Array.from(enabledWasmLoadingTypes);
  947. });
  948. };
  949. /**
  950. * @param {ExternalsPresets} externalsPresets options
  951. * @param {Object} options options
  952. * @param {TargetProperties | false} options.targetProperties target properties
  953. * @param {boolean} options.buildHttp buildHttp experiment enabled
  954. * @returns {void}
  955. */
  956. const applyExternalsPresetsDefaults = (
  957. externalsPresets,
  958. { targetProperties, buildHttp }
  959. ) => {
  960. D(
  961. externalsPresets,
  962. "web",
  963. !buildHttp && targetProperties && targetProperties.web
  964. );
  965. D(externalsPresets, "node", targetProperties && targetProperties.node);
  966. D(externalsPresets, "nwjs", targetProperties && targetProperties.nwjs);
  967. D(
  968. externalsPresets,
  969. "electron",
  970. targetProperties && targetProperties.electron
  971. );
  972. D(
  973. externalsPresets,
  974. "electronMain",
  975. targetProperties &&
  976. targetProperties.electron &&
  977. targetProperties.electronMain
  978. );
  979. D(
  980. externalsPresets,
  981. "electronPreload",
  982. targetProperties &&
  983. targetProperties.electron &&
  984. targetProperties.electronPreload
  985. );
  986. D(
  987. externalsPresets,
  988. "electronRenderer",
  989. targetProperties &&
  990. targetProperties.electron &&
  991. targetProperties.electronRenderer
  992. );
  993. };
  994. /**
  995. * @param {Loader} loader options
  996. * @param {Object} options options
  997. * @param {TargetProperties | false} options.targetProperties target properties
  998. * @returns {void}
  999. */
  1000. const applyLoaderDefaults = (loader, { targetProperties }) => {
  1001. F(loader, "target", () => {
  1002. if (targetProperties) {
  1003. if (targetProperties.electron) {
  1004. if (targetProperties.electronMain) return "electron-main";
  1005. if (targetProperties.electronPreload) return "electron-preload";
  1006. if (targetProperties.electronRenderer) return "electron-renderer";
  1007. return "electron";
  1008. }
  1009. if (targetProperties.nwjs) return "nwjs";
  1010. if (targetProperties.node) return "node";
  1011. if (targetProperties.web) return "web";
  1012. }
  1013. });
  1014. };
  1015. /**
  1016. * @param {WebpackNode} node options
  1017. * @param {Object} options options
  1018. * @param {TargetProperties | false} options.targetProperties target properties
  1019. * @param {boolean} options.futureDefaults is future defaults enabled
  1020. * @returns {void}
  1021. */
  1022. const applyNodeDefaults = (node, { futureDefaults, targetProperties }) => {
  1023. if (node === false) return;
  1024. F(node, "global", () => {
  1025. if (targetProperties && targetProperties.global) return false;
  1026. // TODO webpack 6 should always default to false
  1027. return futureDefaults ? "warn" : true;
  1028. });
  1029. F(node, "__filename", () => {
  1030. if (targetProperties && targetProperties.node) return "eval-only";
  1031. // TODO webpack 6 should always default to false
  1032. return futureDefaults ? "warn-mock" : "mock";
  1033. });
  1034. F(node, "__dirname", () => {
  1035. if (targetProperties && targetProperties.node) return "eval-only";
  1036. // TODO webpack 6 should always default to false
  1037. return futureDefaults ? "warn-mock" : "mock";
  1038. });
  1039. };
  1040. /**
  1041. * @param {Performance} performance options
  1042. * @param {Object} options options
  1043. * @param {boolean} options.production is production
  1044. * @returns {void}
  1045. */
  1046. const applyPerformanceDefaults = (performance, { production }) => {
  1047. if (performance === false) return;
  1048. D(performance, "maxAssetSize", 250000);
  1049. D(performance, "maxEntrypointSize", 250000);
  1050. F(performance, "hints", () => (production ? "warning" : false));
  1051. };
  1052. /**
  1053. * @param {Optimization} optimization options
  1054. * @param {Object} options options
  1055. * @param {boolean} options.production is production
  1056. * @param {boolean} options.development is development
  1057. * @param {CssExperimentOptions} options.css is css enabled
  1058. * @param {boolean} options.records using records
  1059. * @returns {void}
  1060. */
  1061. const applyOptimizationDefaults = (
  1062. optimization,
  1063. { production, development, css, records }
  1064. ) => {
  1065. D(optimization, "removeAvailableModules", false);
  1066. D(optimization, "removeEmptyChunks", true);
  1067. D(optimization, "mergeDuplicateChunks", true);
  1068. D(optimization, "flagIncludedChunks", production);
  1069. F(optimization, "moduleIds", () => {
  1070. if (production) return "deterministic";
  1071. if (development) return "named";
  1072. return "natural";
  1073. });
  1074. F(optimization, "chunkIds", () => {
  1075. if (production) return "deterministic";
  1076. if (development) return "named";
  1077. return "natural";
  1078. });
  1079. F(optimization, "sideEffects", () => (production ? true : "flag"));
  1080. D(optimization, "providedExports", true);
  1081. D(optimization, "usedExports", production);
  1082. D(optimization, "innerGraph", production);
  1083. D(optimization, "mangleExports", production);
  1084. D(optimization, "concatenateModules", production);
  1085. D(optimization, "runtimeChunk", false);
  1086. D(optimization, "emitOnErrors", !production);
  1087. D(optimization, "checkWasmTypes", production);
  1088. D(optimization, "mangleWasmImports", false);
  1089. D(optimization, "portableRecords", records);
  1090. D(optimization, "realContentHash", production);
  1091. D(optimization, "minimize", production);
  1092. A(optimization, "minimizer", () => [
  1093. {
  1094. apply: compiler => {
  1095. // Lazy load the Terser plugin
  1096. const TerserPlugin = require("terser-webpack-plugin");
  1097. new TerserPlugin({
  1098. terserOptions: {
  1099. compress: {
  1100. passes: 2
  1101. }
  1102. }
  1103. }).apply(compiler);
  1104. }
  1105. }
  1106. ]);
  1107. F(optimization, "nodeEnv", () => {
  1108. if (production) return "production";
  1109. if (development) return "development";
  1110. return false;
  1111. });
  1112. const { splitChunks } = optimization;
  1113. if (splitChunks) {
  1114. A(splitChunks, "defaultSizeTypes", () =>
  1115. css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
  1116. );
  1117. D(splitChunks, "hidePathInfo", production);
  1118. D(splitChunks, "chunks", "async");
  1119. D(splitChunks, "usedExports", optimization.usedExports === true);
  1120. D(splitChunks, "minChunks", 1);
  1121. F(splitChunks, "minSize", () => (production ? 20000 : 10000));
  1122. F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined));
  1123. F(splitChunks, "enforceSizeThreshold", () => (production ? 50000 : 30000));
  1124. F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity));
  1125. F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity));
  1126. D(splitChunks, "automaticNameDelimiter", "-");
  1127. const { cacheGroups } = splitChunks;
  1128. F(cacheGroups, "default", () => ({
  1129. idHint: "",
  1130. reuseExistingChunk: true,
  1131. minChunks: 2,
  1132. priority: -20
  1133. }));
  1134. F(cacheGroups, "defaultVendors", () => ({
  1135. idHint: "vendors",
  1136. reuseExistingChunk: true,
  1137. test: NODE_MODULES_REGEXP,
  1138. priority: -10
  1139. }));
  1140. }
  1141. };
  1142. /**
  1143. * @param {Object} options options
  1144. * @param {boolean} options.cache is cache enable
  1145. * @param {string} options.context build context
  1146. * @param {TargetProperties | false} options.targetProperties target properties
  1147. * @param {Mode} options.mode mode
  1148. * @returns {ResolveOptions} resolve options
  1149. */
  1150. const getResolveDefaults = ({ cache, context, targetProperties, mode }) => {
  1151. /** @type {string[]} */
  1152. const conditions = ["webpack"];
  1153. conditions.push(mode === "development" ? "development" : "production");
  1154. if (targetProperties) {
  1155. if (targetProperties.webworker) conditions.push("worker");
  1156. if (targetProperties.node) conditions.push("node");
  1157. if (targetProperties.web) conditions.push("browser");
  1158. if (targetProperties.electron) conditions.push("electron");
  1159. if (targetProperties.nwjs) conditions.push("nwjs");
  1160. }
  1161. const jsExtensions = [".js", ".json", ".wasm"];
  1162. const tp = targetProperties;
  1163. const browserField =
  1164. tp && tp.web && (!tp.node || (tp.electron && tp.electronRenderer));
  1165. /** @type {function(): ResolveOptions} */
  1166. const cjsDeps = () => ({
  1167. aliasFields: browserField ? ["browser"] : [],
  1168. mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."],
  1169. conditionNames: ["require", "module", "..."],
  1170. extensions: [...jsExtensions]
  1171. });
  1172. /** @type {function(): ResolveOptions} */
  1173. const esmDeps = () => ({
  1174. aliasFields: browserField ? ["browser"] : [],
  1175. mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."],
  1176. conditionNames: ["import", "module", "..."],
  1177. extensions: [...jsExtensions]
  1178. });
  1179. /** @type {ResolveOptions} */
  1180. const resolveOptions = {
  1181. cache,
  1182. modules: ["node_modules"],
  1183. conditionNames: conditions,
  1184. mainFiles: ["index"],
  1185. extensions: [],
  1186. aliasFields: [],
  1187. exportsFields: ["exports"],
  1188. roots: [context],
  1189. mainFields: ["main"],
  1190. byDependency: {
  1191. wasm: esmDeps(),
  1192. esm: esmDeps(),
  1193. loaderImport: esmDeps(),
  1194. url: {
  1195. preferRelative: true
  1196. },
  1197. worker: {
  1198. ...esmDeps(),
  1199. preferRelative: true
  1200. },
  1201. commonjs: cjsDeps(),
  1202. amd: cjsDeps(),
  1203. // for backward-compat: loadModule
  1204. loader: cjsDeps(),
  1205. // for backward-compat: Custom Dependency
  1206. unknown: cjsDeps(),
  1207. // for backward-compat: getResolve without dependencyType
  1208. undefined: cjsDeps()
  1209. }
  1210. };
  1211. return resolveOptions;
  1212. };
  1213. /**
  1214. * @param {Object} options options
  1215. * @param {boolean} options.cache is cache enable
  1216. * @returns {ResolveOptions} resolve options
  1217. */
  1218. const getResolveLoaderDefaults = ({ cache }) => {
  1219. /** @type {ResolveOptions} */
  1220. const resolveOptions = {
  1221. cache,
  1222. conditionNames: ["loader", "require", "node"],
  1223. exportsFields: ["exports"],
  1224. mainFields: ["loader", "main"],
  1225. extensions: [".js"],
  1226. mainFiles: ["index"]
  1227. };
  1228. return resolveOptions;
  1229. };
  1230. /**
  1231. * @param {InfrastructureLogging} infrastructureLogging options
  1232. * @returns {void}
  1233. */
  1234. const applyInfrastructureLoggingDefaults = infrastructureLogging => {
  1235. F(infrastructureLogging, "stream", () => process.stderr);
  1236. const tty =
  1237. /** @type {any} */ (infrastructureLogging.stream).isTTY &&
  1238. process.env.TERM !== "dumb";
  1239. D(infrastructureLogging, "level", "info");
  1240. D(infrastructureLogging, "debug", false);
  1241. D(infrastructureLogging, "colors", tty);
  1242. D(infrastructureLogging, "appendOnly", !tty);
  1243. };
  1244. exports.applyWebpackOptionsBaseDefaults = applyWebpackOptionsBaseDefaults;
  1245. exports.applyWebpackOptionsDefaults = applyWebpackOptionsDefaults;