diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 25051afd..ea73174d 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -635,7 +635,7 @@ test("nested", async () => { const inSource = `${outDir}/this/is/nested/${map.sources[0]}`; await expect(fs.pathExists(inSource)).resolves.toBeTruthy(); const source = await fs.readFile(inSource, "utf8"); - expect(map.sourcesContent && map.sourcesContent[0]).toBe(source); + expect(map.sourcesContent?.[0]).toBe(source); }); test("augment-chunk-hash", async () => { diff --git a/src/index.ts b/src/index.ts index 2f1a149c..c67d8d4b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -178,7 +178,10 @@ export default (options: Options = {}): Plugin => { const getName = (chunk: OutputChunk): string => { if (opts.file) return path.basename(opts.file, path.extname(opts.file)); - if (preserveModules) return path.basename(chunk.fileName, path.extname(chunk.fileName)); + if (preserveModules) { + const { dir, name } = path.parse(chunk.fileName); + return dir ? `${dir}/${name}` : name; + } return chunk.name; };