Skip to content

Commit

Permalink
Use entryFileNames for virtual files when preserveModules is set
Browse files Browse the repository at this point in the history
  • Loading branch information
BPScott committed Nov 14, 2021
1 parent 66b3139 commit 6c54b4f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Chunk.ts
Expand Up @@ -434,12 +434,13 @@ export default class Chunk {
const id = this.orderedModules[0].id;
const sanitizedId = this.outputOptions.sanitizeFileName(id);
let path: string;
const pattern = unsetOptions.has('entryFileNames')
? '[name][assetExtname].js'
: options.entryFileNames;

if (isAbsolute(id)) {
const extension = extname(id);
const pattern = unsetOptions.has('entryFileNames')
? '[name][assetExtname].js'
: options.entryFileNames;
const currentDir = dirname(sanitizedId);
const extension = extname(id);
const fileName = renderNamePattern(
typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern,
'output.entryFileNames',
Expand All @@ -459,7 +460,19 @@ export default class Chunk {
path = relative(preserveModulesRelativeDir, currentPath);
}
} else {
path = `_virtual/${basename(sanitizedId)}`;
const extension = extname(sanitizedId);
const fileName = renderNamePattern(
typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern,
'output.entryFileNames',
{
assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension),
ext: () => extension.substr(1),
extname: () => extension,
format: () => options.format as string,
name: () => getAliasName(sanitizedId)
}
);
path = `_virtual/${fileName}`;
}
return makeUnique(normalize(path), existingNames);
}
Expand Down

0 comments on commit 6c54b4f

Please sign in to comment.