Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion packages/compass-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Loading