DepBlockHelpers.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. var DepBlockHelpers = exports;
  6. DepBlockHelpers.getLoadDepBlockWrapper = function(depBlock, outputOptions, requestShortener, name) {
  7. var promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
  8. return [
  9. promiseCode + ".then(",
  10. ").catch(",
  11. ")"
  12. ];
  13. };
  14. DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestShortener, name) {
  15. if(depBlock.chunks) {
  16. var chunks = depBlock.chunks.filter(function(chunk) {
  17. return !chunk.hasRuntime() && chunk.id !== null;
  18. });
  19. if(chunks.length === 1) {
  20. var chunk = chunks[0];
  21. return "__webpack_require__.e" + asComment(name) + "(" + JSON.stringify(chunk.id) + "" +
  22. (outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
  23. asComment(depBlock.chunkReason) + ")";
  24. } else if(chunks.length > 0) {
  25. return "Promise.all" + asComment(name) + "(" +
  26. (outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
  27. "[" +
  28. chunks.map(function(chunk) {
  29. return "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
  30. }).join(", ") +
  31. "])";
  32. }
  33. }
  34. return "new Promise(function(resolve) { resolve(); })";
  35. };
  36. function asComment(str) {
  37. if(!str) return "";
  38. return "/* " + str + " */";
  39. }