WebpackOptionsDefaulter.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const OptionsDefaulter = require("./OptionsDefaulter");
  7. const Template = require("./Template");
  8. class WebpackOptionsDefaulter extends OptionsDefaulter {
  9. constructor() {
  10. super();
  11. this.set("devtool", false);
  12. this.set("cache", true);
  13. this.set("context", process.cwd());
  14. this.set("target", "web");
  15. this.set("module.unknownContextRequest", ".");
  16. this.set("module.unknownContextRegExp", false);
  17. this.set("module.unknownContextRecursive", true);
  18. this.set("module.unknownContextCritical", true);
  19. this.set("module.exprContextRequest", ".");
  20. this.set("module.exprContextRegExp", false);
  21. this.set("module.exprContextRecursive", true);
  22. this.set("module.exprContextCritical", true);
  23. this.set("module.wrappedContextRegExp", /.*/);
  24. this.set("module.wrappedContextRecursive", true);
  25. this.set("module.wrappedContextCritical", false);
  26. this.set("module.strictExportPresence", false);
  27. this.set("module.unsafeCache", true);
  28. this.set("output", "call", (value, options) => {
  29. if(typeof value === "string") {
  30. return {
  31. filename: value
  32. };
  33. } else if(typeof value !== "object") {
  34. return {};
  35. } else {
  36. return value;
  37. }
  38. });
  39. this.set("output.filename", "[name].js");
  40. this.set("output.chunkFilename", "make", (options) => {
  41. const filename = options.output.filename;
  42. return filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename;
  43. });
  44. this.set("output.library", "");
  45. this.set("output.hotUpdateFunction", "make", (options) => {
  46. return Template.toIdentifier("webpackHotUpdate" + options.output.library);
  47. });
  48. this.set("output.jsonpFunction", "make", (options) => {
  49. return Template.toIdentifier("webpackJsonp" + options.output.library);
  50. });
  51. this.set("output.libraryTarget", "var");
  52. this.set("output.path", process.cwd());
  53. this.set("output.sourceMapFilename", "[file].map[query]");
  54. this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
  55. this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
  56. this.set("output.crossOriginLoading", false);
  57. this.set("output.chunkLoadTimeout", 120000);
  58. this.set("output.hashFunction", "md5");
  59. this.set("output.hashDigest", "hex");
  60. this.set("output.hashDigestLength", 20);
  61. this.set("output.devtoolLineToLine", false);
  62. this.set("output.strictModuleExceptionHandling", false);
  63. this.set("node", {});
  64. this.set("node.console", false);
  65. this.set("node.process", true);
  66. this.set("node.global", true);
  67. this.set("node.Buffer", true);
  68. this.set("node.setImmediate", true);
  69. this.set("node.__filename", "mock");
  70. this.set("node.__dirname", "mock");
  71. this.set("performance.maxAssetSize", 250000);
  72. this.set("performance.maxEntrypointSize", 250000);
  73. this.set("performance.hints", false);
  74. this.set("resolve", {});
  75. this.set("resolve.unsafeCache", true);
  76. this.set("resolve.modules", ["node_modules"]);
  77. this.set("resolve.extensions", [".js", ".json"]);
  78. this.set("resolve.aliasFields", "make", (options) => {
  79. if(options.target === "web" || options.target === "webworker")
  80. return ["browser"];
  81. else
  82. return [];
  83. });
  84. this.set("resolve.mainFields", "make", (options) => {
  85. if(options.target === "web" || options.target === "webworker")
  86. return ["browser", "module", "main"];
  87. else
  88. return ["module", "main"];
  89. });
  90. this.set("resolveLoader", {});
  91. this.set("resolveLoader.unsafeCache", true);
  92. this.set("resolveLoader.mainFields", ["loader", "main"]);
  93. this.set("resolveLoader.extensions", [".js", ".json"]);
  94. }
  95. }
  96. module.exports = WebpackOptionsDefaulter;