webapp/vite.config.ts

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-10-03 12:27:43 +00:00
// biome-ignore lint/correctness/noNodejsModules: build
2024-09-15 19:39:32 +00:00
import path from 'node:path'
2024-09-24 06:48:39 +00:00
import dotenv from 'dotenv'
2024-10-03 12:27:43 +00:00
import { CSSOptions, defineConfig } from 'vite'
2024-09-12 06:56:53 +00:00
import mkcert from 'vite-plugin-mkcert'
import { PolyfillOptions, nodePolyfills } from 'vite-plugin-node-polyfills'
import sassDts from 'vite-plugin-sass-dts'
2024-09-24 06:48:39 +00:00
// Load environment variables from .env file
dotenv.config()
export const isDev = process.env.NODE_ENV !== 'production'
console.log(`[vite.config] ${process.env.NODE_ENV} mode`)
2024-09-12 06:56:53 +00:00
const polyfillOptions = {
include: ['path', 'stream', 'util'],
exclude: ['http'],
2024-09-24 06:48:39 +00:00
globals: { Buffer: true },
overrides: { fs: 'memfs' },
2024-09-12 06:56:53 +00:00
protocolImports: true
} as PolyfillOptions
2024-10-03 12:27:43 +00:00
export default defineConfig({
2024-09-15 19:39:32 +00:00
resolve: {
alias: {
2024-09-16 12:57:00 +00:00
'~': path.resolve('./src'),
'@': path.resolve('./public'),
'/icons': path.resolve('./public/icons'),
2024-10-03 09:01:44 +00:00
'/fonts': path.resolve('./public/fonts')
2024-09-15 19:39:32 +00:00
}
},
2024-09-12 06:56:53 +00:00
envPrefix: 'PUBLIC_',
2024-09-15 19:39:32 +00:00
plugins: [isDev && mkcert(), nodePolyfills(polyfillOptions), sassDts()],
2024-09-12 06:56:53 +00:00
css: {
preprocessorOptions: {
scss: {
2024-10-03 12:57:22 +00:00
silenceDeprecations: ['mixed-decls', 'legacy-js-api'],
2024-10-03 09:01:44 +00:00
additionalData: '@import "~/styles/inject";\n',
2024-09-16 12:57:00 +00:00
includePaths: ['./public', './src/styles', './node_modules']
2024-09-12 06:56:53 +00:00
}
} as CSSOptions['preprocessorOptions']
},
build: {
target: 'esnext',
sourcemap: true,
2024-09-24 06:48:39 +00:00
minify: 'terser', // explicit terser usage
terserOptions: {
compress: {
drop_console: true // removes console logs in production
}
},
2024-09-12 06:56:53 +00:00
rollupOptions: {
// plugins: [visualizer()]
output: {
manualChunks: {
icons: ['./src/components/_shared/Icon/Icon.tsx'],
session: ['./src/context/session.tsx'],
2024-09-24 06:48:39 +00:00
localize: ['./src/context/localize.tsx'],
2024-09-12 06:56:53 +00:00
editor: ['./src/context/editor.tsx'],
connect: ['./src/context/connect.tsx']
}
}
2024-10-03 12:27:43 +00:00
},
commonjsOptions: {
ignore: ['punycode']
2024-09-12 06:56:53 +00:00
}
2024-10-03 12:27:43 +00:00
},
optimizeDeps: {
include: ['solid-tiptap'],
exclude: ['punycode']
2024-09-12 06:56:53 +00:00
}
2024-10-03 12:27:43 +00:00
})