From 6e28e3ab727260dcea6117207ad0e9acb4e7b9e3 Mon Sep 17 00:00:00 2001 From: shellscape Date: Tue, 1 Dec 2020 21:50:43 -0500 Subject: [PATCH] fix: rebase pr onto upstream/master --- lib/hooks.js | 7 ++++--- test/unit/paths.js | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/hooks.js b/lib/hooks.js index eb78fdc..b3021f2 100644 --- a/lib/hooks.js +++ b/lib/hooks.js @@ -33,10 +33,11 @@ const emitHook = function emit( compilation ) { const emitCount = emitCountMap.get(manifestFileName) - 1; - const publicPath = - options.publicPath !== null ? options.publicPath : compilation.options.output.publicPath; // Disable everything we don't use, add asset info, show cached assets - const stats = compilation.getStats().toJson({ all: false, assets: true, cachedAssets: true }); + const stats = compilation + .getStats() + .toJson({ all: false, assets: true, cachedAssets: true, publicPath: true }); + const publicPath = options.publicPath !== null ? options.publicPath : stats.publicPath; const { basePath, removeKeyHash } = options; emitCountMap.set(manifestFileName, emitCount); diff --git a/test/unit/paths.js b/test/unit/paths.js index 2009416..ff1129c 100644 --- a/test/unit/paths.js +++ b/test/unit/paths.js @@ -72,7 +72,26 @@ test('prefixes paths with a public path', async (t) => { }); }); -test('is possible to overrides publicPath', async (t) => { +test('prefixes paths with a public path and handle [hash] from public path', async (t) => { + const config = { + context: __dirname, + entry: { + one: '../fixtures/file.js' + }, + output: { + filename: '[name].js', + path: join(outputPath, 'public-hash'), + publicPath: '/[hash]/app/' + } + }; + const { manifest, stats } = await compile(config, t); + + t.deepEqual(manifest, { + 'one.js': `/${stats.hash}/app/one.js` + }); +}); + +test('is possible to override publicPath', async (t) => { const config = { context: __dirname, entry: {