import { visualizer } from 'rollup-plugin-visualizer'; import { defineConfig, type UserConfig } from 'vite'; import checker from 'vite-plugin-checker'; import path, { join } from 'path'; // https://vitejs.dev/config/ export default defineConfig(async ({ mode }): Promise => { const config: UserConfig = { // https://vitejs.dev/config/#server-options server: { fs: { // Allow serving files from one level up to the project root allow: ['..'], }, }, resolve: { alias: [ { find: /~(.+)/, replacement: join(process.cwd(), 'node_modules/$1'), }, ], }, plugins: [ // vite-plugin-checker // https://github.com/fi3ework/vite-plugin-checker checker({ typescript: true, vueTsc: false, eslint: { lintCommand: 'eslint', // for example, lint .ts & .tsx }, }), ], // Build Options // https://vitejs.dev/config/#build-options build: { lib: { entry: path.resolve(__dirname, 'src/index.ts'), name: 'InertiaComposable', fileName: format => `index.${format}.js`, }, rollupOptions: { plugins: [ mode === 'analyze' ? // rollup-plugin-visualizer // https://github.com/btd/rollup-plugin-visualizer visualizer({ open: true, filename: 'dist/stats.html', gzipSize: true, brotliSize: true, }) : undefined, ], external: [ 'bootstrap/dist/css/bootstrap.css', 'bootstrap/dist/css/bootstrap.css?raw', '@codemirror/language', '@codemirror/state', '@codemirror/view', '@lezer/highlight', ], output: { exports: 'named', globals: { 'bootstrap/dist/css/bootstrap.css?raw': 'bootstrap', '@lezer/highlight': 'highlight', '@codemirror/language': 'language', '@codemirror/lint': 'lint', '@codemirror/state': 'state', '@codemirror/view': 'view', }, }, }, target: 'es2021', /* // Minify option // https://vitejs.dev/config/#build-minify minify: 'terser', terserOptions: { ecma: 2020, parse: {}, compress: { drop_console: true }, mangle: true, // Note `mangle.properties` is `false` by default. module: true, output: { comments: true, beautify: false }, }, */ }, }; /* // Write meta data. fs.writeFileSync( path.resolve(path.join(__dirname, 'src/Meta.ts')), `import type MetaInterface from '@/interfaces/MetaInterface'; // This file is auto-generated by the build system. const meta: MetaInterface = { version: '${require('./package.json').version}', date: '${new Date().toISOString()}', }; export default meta; ` ); */ return config; });