UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7const path_1 = require("path");
8
9const integrity_sha_utils_1 = require("../../../lib/packages/integrity-sha-utils");
10
11function getChunkDependencies({
12 entrypoints,
13 outputOptions
14}, entryName) {
15 const {
16 publicPath = '',
17 hashFunction,
18 hashDigest
19 } = outputOptions;
20 const dependencyChunks = entrypoints.get(entryName).chunks;
21 const allChunkFiles = dependencyChunks.reduce((allFiles, depChunk) => [...allFiles, ...depChunk.files], []);
22 const dependencies = {
23 css: [],
24 js: []
25 };
26 allChunkFiles.forEach(path => {
27 const extension = path_1.extname(path).replace('.', '');
28
29 if (!dependencies[extension]) {
30 dependencies[extension] = [];
31 }
32
33 const integrity = integrity_sha_utils_1.calculateBase64IntegrityFromFilename(path, hashFunction, hashDigest);
34 dependencies[extension].push(Object.assign({
35 path: `${publicPath}${path}`
36 }, integrity ? {
37 integrity
38 } : {}));
39 });
40 return dependencies;
41}
42
43exports.getChunkDependencies = getChunkDependencies;
\No newline at end of file