@@ -165,6 +165,35 @@ function viteLegacyPlugin(options = {}) {
165
165
return
166
166
}
167
167
168
+ /**
169
+ * @param {string|((chunkInfo: import('rollup').PreRenderedChunk)=>string) } fileNames
170
+ * @param {string? } defaultFileName
171
+ */
172
+ const getLegacyOutputFileName = (
173
+ fileNames ,
174
+ defaultFileName = '[name]-legacy.[hash].js'
175
+ ) => {
176
+ if ( ! fileNames ) {
177
+ return path . posix . join ( config . build . assetsDir , defaultFileName )
178
+ }
179
+
180
+ // does not support custom functions.
181
+ if ( typeof fileNames === 'function' ) {
182
+ throw new Error (
183
+ `@vitejs/plugin-legacy rollupOptions.output.entryFileNames and rollupOptions.output.chunkFileNames` +
184
+ ` does not support the function format.`
185
+ )
186
+ }
187
+
188
+ let fileName = defaultFileName
189
+ // Custom string file return format.
190
+ if ( fileNames && typeof fileNames === 'string' ) {
191
+ fileName = fileNames . replace ( / \[ n a m e \] / , '[name]-legacy' )
192
+ }
193
+
194
+ return fileName
195
+ }
196
+
168
197
/**
169
198
* @param {import('rollup').OutputOptions } options
170
199
* @returns {import('rollup').OutputOptions }
@@ -173,14 +202,8 @@ function viteLegacyPlugin(options = {}) {
173
202
return {
174
203
...options ,
175
204
format : 'system' ,
176
- entryFileNames : path . posix . join (
177
- config . build . assetsDir ,
178
- `[name]-legacy.[hash].js`
179
- ) ,
180
- chunkFileNames : path . posix . join (
181
- config . build . assetsDir ,
182
- `[name]-legacy.[hash].js`
183
- )
205
+ entryFileNames : getLegacyOutputFileName ( options . entryFileNames ) ,
206
+ chunkFileNames : getLegacyOutputFileName ( options . chunkFileNames )
184
207
}
185
208
}
186
209
0 commit comments