wallet-core/node_modules/webpack/lib/dependencies/DepBlockHelpers.js

40 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-05-03 15:35:00 +02:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2017-08-14 05:01:11 +02:00
"use strict";
2017-05-03 15:35:00 +02:00
2017-08-14 05:01:11 +02:00
const DepBlockHelpers = exports;
DepBlockHelpers.getLoadDepBlockWrapper = (depBlock, outputOptions, requestShortener, name) => {
const promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
2017-05-03 15:35:00 +02:00
return [
promiseCode + ".then(",
").catch(",
")"
];
};
2017-08-14 05:01:11 +02:00
DepBlockHelpers.getDepBlockPromise = (depBlock, outputOptions, requestShortener, name) => {
2017-05-03 15:35:00 +02:00
if(depBlock.chunks) {
2017-08-14 05:01:11 +02:00
const chunks = depBlock.chunks.filter(chunk => !chunk.hasRuntime() && chunk.id !== null);
const pathChunkCheck = outputOptions.pathinfo && depBlock.chunkName;
const shortChunkName = requestShortener.shorten(depBlock.chunkName);
const chunkReason = asComment(depBlock.chunkReason);
const requireChunkId = chunk => "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
name = asComment(name);
2017-05-03 15:35:00 +02:00
if(chunks.length === 1) {
2017-08-14 05:01:11 +02:00
const chunkId = JSON.stringify(chunks[0].id);
return `__webpack_require__.e${name}(${chunkId}${pathChunkCheck ? "/*! " + shortChunkName + " */" : ""}${chunkReason})`;
2017-05-03 15:35:00 +02:00
} else if(chunks.length > 0) {
2017-08-14 05:01:11 +02:00
return `Promise.all${name}(${pathChunkCheck ? "/*! " + shortChunkName + " */" : ""}[${chunks.map(requireChunkId).join(", ")}])`;
2017-05-03 15:35:00 +02:00
}
}
2017-05-24 15:10:37 +02:00
return "new Promise(function(resolve) { resolve(); })";
2017-05-03 15:35:00 +02:00
};
function asComment(str) {
if(!str) return "";
2017-08-14 05:01:11 +02:00
return `/* ${str} */`;
2017-05-03 15:35:00 +02:00
}