diff --git a/packages/compass-web/webpack.config.js b/packages/compass-web/webpack.config.js index bff3ec5ad3b..8d63c2b2d75 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -163,6 +163,40 @@ module.exports = (env, args) => { process: [localPolyfill('process'), 'process'], }), + // Plugin to collect entrypoint filename information and save it in a + // manifest file + function (compiler) { + compiler.hooks.emit.tap('manifest', function (compilation) { + const stats = compilation.getStats().toJson({ + all: false, + outputPath: true, + entrypoints: true, + }); + + if (!('index' in stats.entrypoints)) { + throw new Error('Missing expected entrypoint in the stats object'); + } + + const assets = JSON.stringify( + stats.entrypoints.index.assets + .map((asset) => { + return asset.name; + }) + // The root entrypoint is at the end of the assets list, but + // we'd want to preload it first, reversing here puts the + // manifest list in the load order we want + .reverse(), + null, + 2 + ); + + compilation.emitAsset( + 'assets-manifest.json', + new webpack.sources.RawSource(assets) + ); + }); + }, + // Only applied when running webpack in --watch mode. In this mode we want // to constantly rebuild d.ts files when source changes, we also don't // want to fail and stop compilation if we failed to generate definitions @@ -251,7 +285,9 @@ module.exports = (env, args) => { config.output = { path: config.output.path, filename: (pathData) => { - return pathData.chunk.hasEntryModule() ? 'compass-web.mjs' : '[name].mjs'; + return pathData.chunk.hasEntryModule() + ? 'compass-web.mjs' + : '[name].[contenthash].mjs'; }, library: { type: 'module',