vite/playground/assets/vite.config-runtime-base.js
翠 / green d5e7db08a4
Some checks are pending
CI / Get changed files (push) Waiting to run
CI / Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }} (18, ubuntu-latest) (push) Blocked by required conditions
CI / Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }} (20, ubuntu-latest) (push) Blocked by required conditions
CI / Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }} (22, macos-latest) (push) Blocked by required conditions
CI / Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }} (22, ubuntu-latest) (push) Blocked by required conditions
CI / Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }} (22, windows-latest) (push) Blocked by required conditions
CI / Build & Test Passed or Skipped (push) Blocked by required conditions
CI / Build & Test Failed (push) Blocked by required conditions
CI / Lint: node-20, ubuntu-latest (push) Waiting to run
Preview release / preview (push) Waiting to run
test: change assets-runtime-base outDir to different one (#18727)
2024-11-21 07:28:40 +01:00

62 lines
1.5 KiB
JavaScript

import { defineConfig } from 'vite'
import baseConfig from './vite.config.js'
const dynamicBaseAssetsCode = `
globalThis.__toAssetUrl = url => '/' + url
globalThis.__publicBase = '/'
`
export default defineConfig({
...baseConfig,
base: './', // overwrite the original base: '/foo/'
build: {
...baseConfig.build,
outDir: 'dist/runtime-base',
watch: null,
minify: false,
assetsInlineLimit: 0,
rollupOptions: {
output: {
entryFileNames: 'entries/[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
assetFileNames: 'other-assets/[name]-[hash][extname]',
},
},
},
plugins: [
{
name: 'dynamic-base-assets-globals',
transformIndexHtml(_, ctx) {
if (ctx.bundle) {
// Only inject during build
return [
{
tag: 'script',
attrs: { type: 'module' },
children: dynamicBaseAssetsCode,
},
]
}
},
},
],
experimental: {
renderBuiltUrl(filename, { hostType, type }) {
if (type === 'asset') {
if (hostType === 'js') {
return {
runtime: `globalThis.__toAssetUrl(${JSON.stringify(filename)})`,
}
}
} else if (type === 'public') {
if (hostType === 'js') {
return {
runtime: `globalThis.__publicBase+${JSON.stringify(filename)}`,
}
}
}
},
},
cacheDir: 'node_modules/.vite-runtime-base',
})