@@ -25,7 +25,7 @@ export type Stage =
2525
2626export interface Options {
2727 disabled ?: boolean
28- name : string | ( ( hash : Compilation [ 'hash' ] ) => string )
28+ name : string | string [ ] | ( ( hash : Compilation [ 'hash' ] ) => string | string [ ] )
2929 content : RawContent | ( ( assets : Compilation [ 'assets' ] ) => PromiseLike < RawContent > | RawContent )
3030 stage ?: Stage
3131}
@@ -39,9 +39,7 @@ export const emitFile = (options: Options): WebpackPluginFunction => {
3939 return
4040 }
4141 compiler . hooks . thisCompilation . tap ( pluginName , ( compilation ) => {
42- const basePath = compilation . options . output . path ?? ''
43- const fileName = typeof options . name === 'function' ? options . name ( compilation . hash ) : options . name
44- const filePath = path . relative ( basePath , path . resolve ( basePath , fileName ) )
42+ const filePath = resolveFilePath ( compilation . options . output . path ?? '' , options . name , compilation . hash )
4543 compilation . hooks . processAssets . tapPromise ( tapOptions , async ( ) => {
4644 const source = await toSource ( options . content , compilation . assets )
4745 if ( source !== null ) {
@@ -76,3 +74,11 @@ async function toSource(input: Options['content'], assets: Compilation['assets']
7674 }
7775 return null
7876}
77+
78+ function resolveFilePath ( basePath : string , name : Options [ 'name' ] , hash ?: string ) {
79+ let parts = typeof name === 'function' ? name ( hash ) : name
80+ if ( ! Array . isArray ( parts ) ) {
81+ parts = [ parts ]
82+ }
83+ return path . relative ( basePath , path . resolve ( basePath , ...parts ) )
84+ }
0 commit comments