Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read publicPath from stats to handle [hash] #215

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 20 additions & 1 deletion test/unit/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down