/// import { defineConfig } from 'vite'; import solidPlugin from 'vite-plugin-solid'; import p from './package.json'; import visualizer from 'rollup-plugin-visualizer'; import fs from 'fs'; export default defineConfig(({ mode }) => { const __isDev__ = mode === 'development'; return { base: './', plugins: [ solidPlugin(), { enforce: 'pre', transformIndexHtml(code) { // 替换 HTML 中的模板位置为搜索引擎的东西 if (!__isDev__) return code.replace( '', fs.readFileSync('./html/searchEngine.html', 'utf8') ); }, resolveId(id) { if (id === 'viewerjs') { return { external: true, id: 'https://cdn.jsdelivr.net/npm/viewerjs/dist/viewer.esm.min.js', }; } }, transform(code, id) { // 兼容 worker 模式 if (!__isDev__ && id.includes('/src/worker/index')) { return code.replace(/{[^{]*?type:\s*?'module',*?[^}]*?}/g, ''); } }, }, mode === 'analyze' && (visualizer({ open: true, filename: 'visualizer/stat.html' }) as any), ], server: { port: 3000, proxy: { // 配合 netlify 的云函数 '/.netlify/functions/notion_get': 'http://localhost:9999/.netlify/functions/notion_get', '/.netlify/functions/notion_create': 'http://localhost:9999/.netlify/functions/notion_create', }, }, resolve: { alias: {}, }, define: { __version__: JSON.stringify(p.version), __isDev__: JSON.stringify(__isDev__), }, build: { rollupOptions: { input: { index: './index.html', gallery: './gallery.html', notebook: './notebook.html', }, }, }, worker: { format: 'iife' }, }; });