1 | import { commentsToConfiguration } from './utils';
|
2 | var preservePrefetch = function (_, __, options) { return !!options.webpackPrefetch; };
|
3 | var preservePreload = function (_, __, options) { return !!options.webpackPreload; };
|
4 | var preserveChunkName = function (_, __, options) {
|
5 | return options.webpackChunkName || options.chunkName;
|
6 | };
|
7 | var chunkComment = function (chunk) { return "webpackChunkName: \"" + chunk + "\""; };
|
8 | var preloadComment = function () { return "webpackPreload: true"; };
|
9 | var prefetchComment = function () { return "webpackPrefetch: true"; };
|
10 | var knownMagics = ['webpackChunkName', 'webpackPrefetch', 'webpackPreload'];
|
11 | var toComments = function (conf) {
|
12 | return Object.keys(conf)
|
13 | .filter(function (key) { return !knownMagics.includes(key); })
|
14 | .reduce(function (acc, key) { return acc.concat([key + ":" + JSON.stringify(conf[key])]); }, []);
|
15 | };
|
16 | var nullish = function (a, b) {
|
17 | if (a === undefined) {
|
18 | return b;
|
19 | }
|
20 | return a;
|
21 | };
|
22 | export var processComment = function (configuration, comments, importName, fileName, options) {
|
23 | var _a = configuration.shouldPrefetch, shouldPrefetch = _a === void 0 ? preservePrefetch : _a, _b = configuration.shouldPreload, shouldPreload = _b === void 0 ? preservePreload : _b, _c = configuration.chunkName, chunkName = _c === void 0 ? preserveChunkName : _c;
|
24 | var importConfiguration = commentsToConfiguration(comments);
|
25 | var newChunkName = nullish(chunkName(importName, fileName, importConfiguration), preserveChunkName(importName, fileName, importConfiguration));
|
26 | var isBootstrapFile = options.isBootstrapFile;
|
27 | return toComments(importConfiguration).concat([
|
28 | !isBootstrapFile && shouldPrefetch(importName, fileName, importConfiguration) ? prefetchComment() : '',
|
29 | !isBootstrapFile && shouldPreload(importName, fileName, importConfiguration) ? preloadComment() : '',
|
30 | newChunkName ? chunkComment(newChunkName) : '',
|
31 | ]).filter(function (x) { return !!x; });
|
32 | };
|