From 010825124f7791dfc0dc607e23ec99f49be8aef5 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 5 May 2026 02:45:25 +0200 Subject: [PATCH] Add import mode for direct importing in vite apps --- package.json | 1 + vite.config.js | 51 ++++++++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index ab7c446..2d14cc0 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dev": "vite", "build": "vite build", "build-dev": "vite build --sourcemap inline", + "build-import": "vite build --mode=import", "preview": "vite preview" }, "dependencies": { diff --git a/vite.config.js b/vite.config.js index 5d8c199..9924253 100644 --- a/vite.config.js +++ b/vite.config.js @@ -2,27 +2,34 @@ import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [ - vue({ - template: { - compilerOptions: { - isCustomElement: (tag) => tag.includes('event-form') || tag.includes('event-index') || tag.includes('event-description'), +export default defineConfig(({mode}) => { + return { + plugins: [ + vue({ + template: { + compilerOptions: { + isCustomElement: (tag) => tag.includes('event-form') || tag.includes('event-index') || tag.includes('event-description'), + }, }, - }, - }), - ], - build: { - manifest: 'manifest.json', - rollupOptions: { - input: 'src/main.js', - } - }, - define: { - 'process.env': process.env, - }, - server: { - port: 5174, - host: '0.0.0.0', - }, + }), + ], + build: { + manifest: 'manifest.json', + rollupOptions: { + input: 'src/main.js', + output: { + entryFileNames: mode === 'import' ? `assets/[name].js` : `assets/[name]-[hash].js`, + chunkFileNames: mode === 'import' ? `assets/[name].js` : `assets/[name]-[hash].js`, + assetFileNames: mode === 'import' ? `assets/[name].[ext]` : `assets/[name]-[hash].[ext]`, + } + } + }, + define: { + 'process.env': process.env, + }, + server: { + port: 5174, + host: '0.0.0.0', + }, + }; });