Initial Version
This commit is contained in:
108
vite.config.ts
Normal file
108
vite.config.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { defineConfig, type PluginOption } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import vuetify from 'vite-plugin-vuetify';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
||||
import { generateVendorShims } from './scripts/generate-vendor-shims';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const runVendorShimGenerator = async (outputDir: string) => {
|
||||
await generateVendorShims({ outputDir, silent: true });
|
||||
};
|
||||
|
||||
const generateVendorShimsPlugin = (): PluginOption => {
|
||||
let outDir = 'dist';
|
||||
let rootDir = process.cwd();
|
||||
|
||||
return {
|
||||
name: 'generate-vendor-shims',
|
||||
apply: 'build',
|
||||
configResolved(config) {
|
||||
outDir = config.build.outDir;
|
||||
rootDir = config.root;
|
||||
},
|
||||
async closeBundle() {
|
||||
try {
|
||||
const resolvedOutDir = path.isAbsolute(outDir) ? outDir : path.resolve(rootDir, outDir);
|
||||
const vendorDestination = path.resolve(resolvedOutDir, 'vendor');
|
||||
await runVendorShimGenerator(vendorDestination);
|
||||
} catch (error) {
|
||||
console.warn('[generate-vendor-shims] Failed to update vendor shims', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(({ mode }) => ({
|
||||
root: path.resolve(__dirname, 'core/src'),
|
||||
plugins: [
|
||||
vue(),
|
||||
vuetify(),
|
||||
generateVendorShimsPlugin(),
|
||||
viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
src: path.resolve(__dirname, 'core/lib/index.php'),
|
||||
dest: path.resolve(__dirname, 'public'),
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@KTXC': path.resolve(__dirname, 'core/src'),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
fs: {
|
||||
allow: ['..'], // Allow serving files from one level up to find the project root
|
||||
},
|
||||
host: true,
|
||||
},
|
||||
build: {
|
||||
outDir: path.resolve(__dirname, 'public'),
|
||||
emptyOutDir: true,
|
||||
minify: mode === 'production',
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
input: {
|
||||
public: path.resolve(__dirname, 'core/src/public.html'),
|
||||
private: path.resolve(__dirname, 'core/src/private.html'),
|
||||
'shared-utils': path.resolve(__dirname, 'core/src/utils/helpers/shared.ts'),
|
||||
},
|
||||
output: {
|
||||
// Preserve export names for shared-utils (used via import map by modules)
|
||||
minifyInternalExports: false,
|
||||
entryFileNames: (chunkInfo) => {
|
||||
// Keep shared-utils without hash for stable import map reference
|
||||
if (chunkInfo.name === 'shared-utils') {
|
||||
return `js/[name].js`;
|
||||
}
|
||||
return `js/[name]-[hash].js`;
|
||||
},
|
||||
chunkFileNames: (chunkInfo) => {
|
||||
return `js/[name]-[hash].js`;
|
||||
},
|
||||
assetFileNames: (assetInfo) => {
|
||||
if (assetInfo.name) {
|
||||
const extType = assetInfo.name.split('.').pop();
|
||||
if (extType && /png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
|
||||
return `images/[name]-[hash][extname]`;
|
||||
}
|
||||
if (extType && /woff|woff2|eot|ttf|otf/i.test(extType)) {
|
||||
return `fonts/[name]-[hash][extname]`;
|
||||
}
|
||||
if (extType === 'css') {
|
||||
return `css/[name]-[hash][extname]`;
|
||||
}
|
||||
}
|
||||
return `[name]-[hash][extname]`;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user