Skip to content

Commit 58057ae

Browse files
authored
chore(web): produce manifest file listing all compass-web assets as part of compilation COMPASS-10131 (#7624)
* chore(web): produce manifest file listing all compass-web assets as part of compilation * fix(web): use emitAssets instead of direct fs call to account for webpack in-memory fs
1 parent da7393a commit 58057ae

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

packages/compass-web/webpack.config.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,40 @@ module.exports = (env, args) => {
163163
process: [localPolyfill('process'), 'process'],
164164
}),
165165

166+
// Plugin to collect entrypoint filename information and save it in a
167+
// manifest file
168+
function (compiler) {
169+
compiler.hooks.emit.tap('manifest', function (compilation) {
170+
const stats = compilation.getStats().toJson({
171+
all: false,
172+
outputPath: true,
173+
entrypoints: true,
174+
});
175+
176+
if (!('index' in stats.entrypoints)) {
177+
throw new Error('Missing expected entrypoint in the stats object');
178+
}
179+
180+
const assets = JSON.stringify(
181+
stats.entrypoints.index.assets
182+
.map((asset) => {
183+
return asset.name;
184+
})
185+
// The root entrypoint is at the end of the assets list, but
186+
// we'd want to preload it first, reversing here puts the
187+
// manifest list in the load order we want
188+
.reverse(),
189+
null,
190+
2
191+
);
192+
193+
compilation.emitAsset(
194+
'assets-manifest.json',
195+
new webpack.sources.RawSource(assets)
196+
);
197+
});
198+
},
199+
166200
// Only applied when running webpack in --watch mode. In this mode we want
167201
// to constantly rebuild d.ts files when source changes, we also don't
168202
// want to fail and stop compilation if we failed to generate definitions
@@ -251,7 +285,9 @@ module.exports = (env, args) => {
251285
config.output = {
252286
path: config.output.path,
253287
filename: (pathData) => {
254-
return pathData.chunk.hasEntryModule() ? 'compass-web.mjs' : '[name].mjs';
288+
return pathData.chunk.hasEntryModule()
289+
? 'compass-web.mjs'
290+
: '[name].[contenthash].mjs';
255291
},
256292
library: {
257293
type: 'module',

0 commit comments

Comments
 (0)