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