mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
Co-authored-by: Shinigami <chrissi92@hotmail.de>
This commit is contained in:
parent
05bd96e21c
commit
d852731622
@ -5,6 +5,7 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build --debug legacy",
|
||||
"build:custom-filename": "vite --config ./vite.config-custom-filename.js build --debug legacy",
|
||||
"debug": "node --inspect-brk ../../vite/bin/vite",
|
||||
"serve": "vite preview"
|
||||
},
|
||||
|
15
packages/playground/legacy/vite.config-custom-filename.js
Normal file
15
packages/playground/legacy/vite.config-custom-filename.js
Normal file
@ -0,0 +1,15 @@
|
||||
const legacy = require('@vitejs/plugin-legacy').default
|
||||
|
||||
module.exports = {
|
||||
plugins: [legacy()],
|
||||
build: {
|
||||
manifest: true,
|
||||
minify: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
entryFileNames: `assets/[name].js`,
|
||||
chunkFileNames: `assets/[name].js`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -165,6 +165,35 @@ function viteLegacyPlugin(options = {}) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|((chunkInfo: import('rollup').PreRenderedChunk)=>string)} fileNames
|
||||
* @param {string?} defaultFileName
|
||||
*/
|
||||
const getLegacyOutputFileName = (
|
||||
fileNames,
|
||||
defaultFileName = '[name]-legacy.[hash].js'
|
||||
) => {
|
||||
if (!fileNames) {
|
||||
return path.posix.join(config.build.assetsDir, defaultFileName)
|
||||
}
|
||||
|
||||
// does not support custom functions.
|
||||
if (typeof fileNames === 'function') {
|
||||
throw new Error(
|
||||
`@vitejs/plugin-legacy rollupOptions.output.entryFileNames and rollupOptions.output.chunkFileNames` +
|
||||
` does not support the function format.`
|
||||
)
|
||||
}
|
||||
|
||||
let fileName = defaultFileName
|
||||
// Custom string file return format.
|
||||
if (fileNames && typeof fileNames === 'string') {
|
||||
fileName = fileNames.replace(/\[name\]/, '[name]-legacy')
|
||||
}
|
||||
|
||||
return fileName
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('rollup').OutputOptions} options
|
||||
* @returns {import('rollup').OutputOptions}
|
||||
@ -173,14 +202,8 @@ function viteLegacyPlugin(options = {}) {
|
||||
return {
|
||||
...options,
|
||||
format: 'system',
|
||||
entryFileNames: path.posix.join(
|
||||
config.build.assetsDir,
|
||||
`[name]-legacy.[hash].js`
|
||||
),
|
||||
chunkFileNames: path.posix.join(
|
||||
config.build.assetsDir,
|
||||
`[name]-legacy.[hash].js`
|
||||
)
|
||||
entryFileNames: getLegacyOutputFileName(options.entryFileNames),
|
||||
chunkFileNames: getLegacyOutputFileName(options.chunkFileNames)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user