1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | const path_1 = require("path");
|
8 |
|
9 | const url = require("url");
|
10 |
|
11 | const integrity_sha_utils_1 = require("../../../lib/packages/integrity-sha-utils");
|
12 |
|
13 | function getAssetManifest(assetBasePath, compilation) {
|
14 | return Object.values(compilation.assets).reduce((assets, {
|
15 | existsAt
|
16 | }, index) => {
|
17 | assets.all[index] = path_1.relative(assetBasePath, existsAt);
|
18 | return assets;
|
19 | },
|
20 |
|
21 | {
|
22 | all: {}
|
23 | });
|
24 | }
|
25 |
|
26 | exports.getAssetManifest = getAssetManifest;
|
27 |
|
28 | function getAsyncAssetManifest(compilation, {
|
29 | includeIntegrity = true
|
30 | } = {}) {
|
31 | const {
|
32 | hashFunction,
|
33 | hashDigest,
|
34 | publicPath
|
35 | } = compilation.outputOptions;
|
36 | const manifest = {};
|
37 |
|
38 | for (const chunkGroup of compilation.chunkGroups) {
|
39 | const files = [];
|
40 |
|
41 | for (const chunk of chunkGroup.chunks) {
|
42 | for (const file of chunk.files) {
|
43 | if (!file.endsWith('.map')) {
|
44 | const integrity = includeIntegrity && integrity_sha_utils_1.calculateBase64IntegrityFromFilename(file, hashFunction, hashDigest);
|
45 | const fileIntegrity = integrity ? {
|
46 | integrity
|
47 | } : {};
|
48 | files.push(Object.assign({
|
49 | file,
|
50 | publicPath: url.resolve(publicPath || '', file)
|
51 | }, fileIntegrity));
|
52 | }
|
53 | }
|
54 | }
|
55 |
|
56 | for (const block of chunkGroup.blocksIterable) {
|
57 | let id = null;
|
58 | const dependency = block.module == null ? null : block.module.dependencies.find(dep => block.request === dep.request);
|
59 |
|
60 | if (dependency) {
|
61 | const module = dependency.module;
|
62 | id = module.id;
|
63 | }
|
64 |
|
65 | if (id != null) {
|
66 | for (const file of files) {
|
67 | file.id = id;
|
68 | }
|
69 |
|
70 | manifest[id] = files;
|
71 | }
|
72 | }
|
73 | }
|
74 |
|
75 | return manifest;
|
76 | }
|
77 |
|
78 | exports.getAsyncAssetManifest = getAsyncAssetManifest; |
\ | No newline at end of file |