webpack 3.5.5 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Template.js CHANGED
@@ -1,166 +1,176 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const Tapable = require("tapable");
8
- const ConcatSource = require("webpack-sources").ConcatSource;
9
-
10
- const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
11
- const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
12
- const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
13
-
14
- module.exports = class Template extends Tapable {
15
- constructor(outputOptions) {
16
- super();
17
- this.outputOptions = outputOptions || {};
18
- }
19
-
20
- static getFunctionContent(fn) {
21
- return fn.toString().replace(/^function\s?\(\)\s?\{\n?|\n?\}$/g, "").replace(/^\t/mg, "");
22
- }
23
-
24
- static toIdentifier(str) {
25
- if(typeof str !== "string") return "";
26
- return str.replace(/^[^a-zA-Z$_]/, "_").replace(/[^a-zA-Z0-9$_]/g, "_");
27
- }
28
-
29
- static toPath(str) {
30
- if(typeof str !== "string") return "";
31
- return str.replace(/[^a-zA-Z0-9_!§$()=\-^°]+/g, "-").replace(/^-|-$/, "");
32
- }
33
-
34
- // map number to a single character a-z, A-Z or <_ + number> if number is too big
35
- static numberToIdentifer(n) {
36
- // lower case
37
- if(n < DELTA_A_TO_Z) return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
38
-
39
- // upper case
40
- n -= DELTA_A_TO_Z;
41
- if(n < DELTA_A_TO_Z) return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
42
-
43
- // fall back to _ + number
44
- n -= DELTA_A_TO_Z;
45
- return "_" + n;
46
- }
47
-
48
- indent(str) {
49
- if(Array.isArray(str)) {
50
- return str.map(this.indent.bind(this)).join("\n");
51
- } else {
52
- str = str.trimRight();
53
- if(!str) return "";
54
- var ind = (str[0] === "\n" ? "" : "\t");
55
- return ind + str.replace(/\n([^\n])/g, "\n\t$1");
56
- }
57
- }
58
-
59
- prefix(str, prefix) {
60
- if(Array.isArray(str)) {
61
- str = str.join("\n");
62
- }
63
- str = str.trim();
64
- if(!str) return "";
65
- const ind = (str[0] === "\n" ? "" : prefix);
66
- return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
67
- }
68
-
69
- asString(str) {
70
- if(Array.isArray(str)) {
71
- return str.join("\n");
72
- }
73
- return str;
74
- }
75
-
76
- getModulesArrayBounds(modules) {
77
- if(!modules.every(moduleIdIsNumber))
78
- return false;
79
- var maxId = -Infinity;
80
- var minId = Infinity;
81
- modules.forEach(function(module) {
82
- if(maxId < module.id) maxId = module.id;
83
- if(minId > module.id) minId = module.id;
84
- });
85
- if(minId < 16 + ("" + minId).length) {
86
- // add minId x ',' instead of 'Array(minId).concat(...)'
87
- minId = 0;
88
- }
89
- var objectOverhead = modules.map(function(module) {
90
- var idLength = (module.id + "").length;
91
- return idLength + 2;
92
- }).reduce(function(a, b) {
93
- return a + b;
94
- }, -1);
95
- var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
96
- return arrayOverhead < objectOverhead ? [minId, maxId] : false;
97
- }
98
-
99
- renderChunkModules(chunk, moduleTemplate, dependencyTemplates, prefix) {
100
- if(!prefix) prefix = "";
101
- var source = new ConcatSource();
102
- if(chunk.getNumberOfModules() === 0) {
103
- source.add("[]");
104
- return source;
105
- }
106
- var removedModules = chunk.removedModules;
107
- var allModules = chunk.mapModules(function(module) {
108
- return {
109
- id: module.id,
110
- source: moduleTemplate.render(module, dependencyTemplates, chunk)
111
- };
112
- });
113
- if(removedModules && removedModules.length > 0) {
114
- removedModules.forEach(function(id) {
115
- allModules.push({
116
- id: id,
117
- source: "false"
118
- });
119
- });
120
- }
121
- var bounds = this.getModulesArrayBounds(allModules);
122
-
123
- if(bounds) {
124
- // Render a spare array
125
- var minId = bounds[0];
126
- var maxId = bounds[1];
127
- if(minId !== 0) source.add("Array(" + minId + ").concat(");
128
- source.add("[\n");
129
- var modules = {};
130
- allModules.forEach(function(module) {
131
- modules[module.id] = module;
132
- });
133
- for(var idx = minId; idx <= maxId; idx++) {
134
- var module = modules[idx];
135
- if(idx !== minId) source.add(",\n");
136
- source.add("/* " + idx + " */");
137
- if(module) {
138
- source.add("\n");
139
- source.add(module.source);
140
- }
141
- }
142
- source.add("\n" + prefix + "]");
143
- if(minId !== 0) source.add(")");
144
- } else {
145
- // Render an object
146
- source.add("{\n");
147
- allModules.sort(function(a, b) {
148
- var aId = a.id + "";
149
- var bId = b.id + "";
150
- if(aId < bId) return -1;
151
- if(aId > bId) return 1;
152
- return 0;
153
- }).forEach(function(module, idx) {
154
- if(idx !== 0) source.add(",\n");
155
- source.add("\n/***/ " + JSON.stringify(module.id) + ":\n");
156
- source.add(module.source);
157
- });
158
- source.add("\n\n" + prefix + "}");
159
- }
160
- return source;
161
- }
162
- };
163
-
164
- function moduleIdIsNumber(module) {
165
- return typeof module.id === "number";
166
- }
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const Tapable = require("tapable");
8
+ const ConcatSource = require("webpack-sources").ConcatSource;
9
+
10
+ const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
11
+ const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
12
+ const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
13
+ const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\n?|\n?\}$/g;
14
+ const INDENT_MULTILINE_REGEX = /^\t/mg;
15
+ const IDENTIFIER_NAME_REPLACE_REGEX = /^[^a-zA-Z$_]/;
16
+ const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$_]/g;
17
+ const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
18
+ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
19
+
20
+ module.exports = class Template extends Tapable {
21
+ constructor(outputOptions) {
22
+ super();
23
+ this.outputOptions = outputOptions || {};
24
+ }
25
+
26
+ static getFunctionContent(fn) {
27
+ return fn.toString().replace(FUNCTION_CONTENT_REGEX, "").replace(INDENT_MULTILINE_REGEX, "");
28
+ }
29
+
30
+ static toIdentifier(str) {
31
+ if(typeof str !== "string") return "";
32
+ return str.replace(IDENTIFIER_NAME_REPLACE_REGEX, "_").replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
33
+ }
34
+
35
+ static toPath(str) {
36
+ if(typeof str !== "string") return "";
37
+ return str.replace(PATH_NAME_NORMALIZE_REPLACE_REGEX, "-").replace(MATCH_PADDED_HYPHENS_REPLACE_REGEX, "");
38
+ }
39
+
40
+ // map number to a single character a-z, A-Z or <_ + number> if number is too big
41
+ static numberToIdentifer(n) {
42
+ // lower case
43
+ if(n < DELTA_A_TO_Z) return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
44
+
45
+ // upper case
46
+ n -= DELTA_A_TO_Z;
47
+ if(n < DELTA_A_TO_Z) return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
48
+
49
+ // fall back to _ + number
50
+ n -= DELTA_A_TO_Z;
51
+ return "_" + n;
52
+ }
53
+
54
+ indent(str) {
55
+ if(Array.isArray(str)) {
56
+ return str.map(this.indent.bind(this)).join("\n");
57
+ } else {
58
+ str = str.trimRight();
59
+ if(!str) return "";
60
+ var ind = (str[0] === "\n" ? "" : "\t");
61
+ return ind + str.replace(/\n([^\n])/g, "\n\t$1");
62
+ }
63
+ }
64
+
65
+ prefix(str, prefix) {
66
+ if(Array.isArray(str)) {
67
+ str = str.join("\n");
68
+ }
69
+ str = str.trim();
70
+ if(!str) return "";
71
+ const ind = (str[0] === "\n" ? "" : prefix);
72
+ return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
73
+ }
74
+
75
+ asString(str) {
76
+ if(Array.isArray(str)) {
77
+ return str.join("\n");
78
+ }
79
+ return str;
80
+ }
81
+
82
+ getModulesArrayBounds(modules) {
83
+ if(!modules.every(moduleIdIsNumber))
84
+ return false;
85
+ var maxId = -Infinity;
86
+ var minId = Infinity;
87
+ modules.forEach(function(module) {
88
+ if(maxId < module.id) maxId = module.id;
89
+ if(minId > module.id) minId = module.id;
90
+ });
91
+ if(minId < 16 + ("" + minId).length) {
92
+ // add minId x ',' instead of 'Array(minId).concat(...)'
93
+ minId = 0;
94
+ }
95
+ var objectOverhead = modules.map(function(module) {
96
+ var idLength = (module.id + "").length;
97
+ return idLength + 2;
98
+ }).reduce(function(a, b) {
99
+ return a + b;
100
+ }, -1);
101
+ var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
102
+ return arrayOverhead < objectOverhead ? [minId, maxId] : false;
103
+ }
104
+
105
+ renderChunkModules(chunk, moduleTemplate, dependencyTemplates, prefix) {
106
+ if(!prefix) prefix = "";
107
+ var source = new ConcatSource();
108
+ if(chunk.getNumberOfModules() === 0) {
109
+ source.add("[]");
110
+ return source;
111
+ }
112
+ var removedModules = chunk.removedModules;
113
+ var allModules = chunk.mapModules(function(module) {
114
+ return {
115
+ id: module.id,
116
+ source: moduleTemplate.render(module, dependencyTemplates, chunk)
117
+ };
118
+ });
119
+ if(removedModules && removedModules.length > 0) {
120
+ removedModules.forEach(function(id) {
121
+ allModules.push({
122
+ id: id,
123
+ source: "false"
124
+ });
125
+ });
126
+ }
127
+ var bounds = this.getModulesArrayBounds(allModules);
128
+
129
+ if(bounds) {
130
+ // Render a spare array
131
+ var minId = bounds[0];
132
+ var maxId = bounds[1];
133
+ if(minId !== 0) source.add("Array(" + minId + ").concat(");
134
+ source.add("[\n");
135
+ var modules = {};
136
+ allModules.forEach(function(module) {
137
+ modules[module.id] = module;
138
+ });
139
+ for(var idx = minId; idx <= maxId; idx++) {
140
+ var module = modules[idx];
141
+ if(idx !== minId) source.add(",\n");
142
+ source.add("/* " + idx + " */");
143
+ if(module) {
144
+ source.add("\n");
145
+ source.add(module.source);
146
+ }
147
+ }
148
+ source.add("\n" + prefix + "]");
149
+ if(minId !== 0) source.add(")");
150
+ } else {
151
+ // Render an object
152
+ source.add("{\n");
153
+ allModules
154
+ .sort(stringifyIdSortPredicate)
155
+ .forEach(function(module, idx) {
156
+ if(idx !== 0) source.add(",\n");
157
+ source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
158
+ source.add(module.source);
159
+ });
160
+ source.add("\n\n" + prefix + "}");
161
+ }
162
+ return source;
163
+ }
164
+ };
165
+
166
+ function stringifyIdSortPredicate(a, b) {
167
+ var aId = a.id + "";
168
+ var bId = b.id + "";
169
+ if(aId < bId) return -1;
170
+ if(aId > bId) return 1;
171
+ return 0;
172
+ }
173
+
174
+ function moduleIdIsNumber(module) {
175
+ return typeof module.id === "number";
176
+ }
@@ -1,115 +1,129 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const OptionsDefaulter = require("./OptionsDefaulter");
8
- const Template = require("./Template");
9
-
10
- class WebpackOptionsDefaulter extends OptionsDefaulter {
11
- constructor() {
12
- super();
13
- this.set("devtool", false);
14
- this.set("cache", true);
15
-
16
- this.set("context", process.cwd());
17
- this.set("target", "web");
18
-
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);
30
- this.set("module.strictExportPresence", false);
31
- this.set("module.strictThisContextOnImports", false);
32
-
33
- this.set("module.unsafeCache", true);
34
-
35
- this.set("output", "call", (value, options) => {
36
- if(typeof value === "string") {
37
- return {
38
- filename: value
39
- };
40
- } else if(typeof value !== "object") {
41
- return {};
42
- } else {
43
- return value;
44
- }
45
- });
46
- this.set("output.filename", "[name].js");
47
- this.set("output.chunkFilename", "make", (options) => {
48
- const filename = options.output.filename;
49
- return filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename;
50
- });
51
- this.set("output.library", "");
52
- this.set("output.hotUpdateFunction", "make", (options) => {
53
- return Template.toIdentifier("webpackHotUpdate" + options.output.library);
54
- });
55
- this.set("output.jsonpFunction", "make", (options) => {
56
- return Template.toIdentifier("webpackJsonp" + options.output.library);
57
- });
58
- this.set("output.libraryTarget", "var");
59
- this.set("output.path", process.cwd());
60
- this.set("output.sourceMapFilename", "[file].map[query]");
61
- this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
62
- this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
63
- this.set("output.crossOriginLoading", false);
64
- this.set("output.chunkLoadTimeout", 120000);
65
- this.set("output.hashFunction", "md5");
66
- this.set("output.hashDigest", "hex");
67
- this.set("output.hashDigestLength", 20);
68
- this.set("output.devtoolLineToLine", false);
69
- this.set("output.strictModuleExceptionHandling", false);
70
-
71
- this.set("node", {});
72
- this.set("node.console", false);
73
- this.set("node.process", true);
74
- this.set("node.global", true);
75
- this.set("node.Buffer", true);
76
- this.set("node.setImmediate", true);
77
- this.set("node.__filename", "mock");
78
- this.set("node.__dirname", "mock");
79
-
80
- this.set("performance.maxAssetSize", 250000);
81
- this.set("performance.maxEntrypointSize", 250000);
82
- this.set("performance.hints", false);
83
-
84
- this.set("resolve", {});
85
- this.set("resolve.unsafeCache", true);
86
- this.set("resolve.modules", ["node_modules"]);
87
- this.set("resolve.extensions", [".js", ".json"]);
88
- this.set("resolve.mainFiles", ["index"]);
89
- this.set("resolve.aliasFields", "make", (options) => {
90
- if(options.target === "web" || options.target === "webworker")
91
- return ["browser"];
92
- else
93
- return [];
94
- });
95
- this.set("resolve.mainFields", "make", (options) => {
96
- if(options.target === "web" || options.target === "webworker")
97
- return ["browser", "module", "main"];
98
- else
99
- return ["module", "main"];
100
- });
101
- this.set("resolve.cacheWithContext", "make", (options) => {
102
- return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0;
103
- });
104
- this.set("resolveLoader", {});
105
- this.set("resolveLoader.unsafeCache", true);
106
- this.set("resolveLoader.mainFields", ["loader", "main"]);
107
- this.set("resolveLoader.extensions", [".js", ".json"]);
108
- this.set("resolveLoader.mainFiles", ["index"]);
109
- this.set("resolveLoader.cacheWithContext", "make", (options) => {
110
- return Array.isArray(options.resolveLoader.plugins) && options.resolveLoader.plugins.length > 0;
111
- });
112
- }
113
- }
114
-
115
- module.exports = WebpackOptionsDefaulter;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const OptionsDefaulter = require("./OptionsDefaulter");
8
+ const Template = require("./Template");
9
+
10
+ class WebpackOptionsDefaulter extends OptionsDefaulter {
11
+ constructor() {
12
+ super();
13
+ this.set("devtool", false);
14
+ this.set("cache", true);
15
+
16
+ this.set("context", process.cwd());
17
+ this.set("target", "web");
18
+
19
+ this.set("module", "call", value => Object.assign({}, value));
20
+ this.set("module.unknownContextRequest", ".");
21
+ this.set("module.unknownContextRegExp", false);
22
+ this.set("module.unknownContextRecursive", true);
23
+ this.set("module.unknownContextCritical", true);
24
+ this.set("module.exprContextRequest", ".");
25
+ this.set("module.exprContextRegExp", false);
26
+ this.set("module.exprContextRecursive", true);
27
+ this.set("module.exprContextCritical", true);
28
+ this.set("module.wrappedContextRegExp", /.*/);
29
+ this.set("module.wrappedContextRecursive", true);
30
+ this.set("module.wrappedContextCritical", false);
31
+ this.set("module.strictExportPresence", false);
32
+ this.set("module.strictThisContextOnImports", false);
33
+ this.set("module.unsafeCache", true);
34
+
35
+ this.set("output", "call", (value, options) => {
36
+ if(typeof value === "string") {
37
+ return {
38
+ filename: value
39
+ };
40
+ } else if(typeof value !== "object") {
41
+ return {};
42
+ } else {
43
+ return Object.assign({}, value);
44
+ }
45
+ });
46
+ this.set("output.filename", "[name].js");
47
+ this.set("output.chunkFilename", "make", (options) => {
48
+ const filename = options.output.filename;
49
+ return filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename;
50
+ });
51
+ this.set("output.library", "");
52
+ this.set("output.hotUpdateFunction", "make", (options) => {
53
+ return Template.toIdentifier("webpackHotUpdate" + options.output.library);
54
+ });
55
+ this.set("output.jsonpFunction", "make", (options) => {
56
+ return Template.toIdentifier("webpackJsonp" + options.output.library);
57
+ });
58
+ this.set("output.libraryTarget", "var");
59
+ this.set("output.path", process.cwd());
60
+ this.set("output.sourceMapFilename", "[file].map[query]");
61
+ this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
62
+ this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
63
+ this.set("output.crossOriginLoading", false);
64
+ this.set("output.chunkLoadTimeout", 120000);
65
+ this.set("output.hashFunction", "md5");
66
+ this.set("output.hashDigest", "hex");
67
+ this.set("output.hashDigestLength", 20);
68
+ this.set("output.devtoolLineToLine", false);
69
+ this.set("output.strictModuleExceptionHandling", false);
70
+
71
+ this.set("node", "call", value => {
72
+ if(typeof value === "boolean") {
73
+ return value;
74
+ } else {
75
+ return Object.assign({}, value);
76
+ }
77
+ });
78
+ this.set("node.console", false);
79
+ this.set("node.process", true);
80
+ this.set("node.global", true);
81
+ this.set("node.Buffer", true);
82
+ this.set("node.setImmediate", true);
83
+ this.set("node.__filename", "mock");
84
+ this.set("node.__dirname", "mock");
85
+
86
+ this.set("performance", "call", value => {
87
+ if(typeof value === "boolean") {
88
+ return value;
89
+ } else {
90
+ return Object.assign({}, value);
91
+ }
92
+ });
93
+ this.set("performance.maxAssetSize", 250000);
94
+ this.set("performance.maxEntrypointSize", 250000);
95
+ this.set("performance.hints", false);
96
+
97
+ this.set("resolve", "call", value => Object.assign({}, value));
98
+ this.set("resolve.unsafeCache", true);
99
+ this.set("resolve.modules", ["node_modules"]);
100
+ this.set("resolve.extensions", [".js", ".json"]);
101
+ this.set("resolve.mainFiles", ["index"]);
102
+ this.set("resolve.aliasFields", "make", (options) => {
103
+ if(options.target === "web" || options.target === "webworker")
104
+ return ["browser"];
105
+ else
106
+ return [];
107
+ });
108
+ this.set("resolve.mainFields", "make", (options) => {
109
+ if(options.target === "web" || options.target === "webworker")
110
+ return ["browser", "module", "main"];
111
+ else
112
+ return ["module", "main"];
113
+ });
114
+ this.set("resolve.cacheWithContext", "make", (options) => {
115
+ return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0;
116
+ });
117
+
118
+ this.set("resolveLoader", "call", value => Object.assign({}, value));
119
+ this.set("resolveLoader.unsafeCache", true);
120
+ this.set("resolveLoader.mainFields", ["loader", "main"]);
121
+ this.set("resolveLoader.extensions", [".js", ".json"]);
122
+ this.set("resolveLoader.mainFiles", ["index"]);
123
+ this.set("resolveLoader.cacheWithContext", "make", (options) => {
124
+ return Array.isArray(options.resolveLoader.plugins) && options.resolveLoader.plugins.length > 0;
125
+ });
126
+ }
127
+ }
128
+
129
+ module.exports = WebpackOptionsDefaulter;