This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
143 lines (135 loc) · 3.38 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import fs from 'fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
// -- vite --
import { defineConfig } from 'vite'
// -- vite plugins --
import { sveltekit } from '@sveltejs/kit/vite'
import imagePresets, { widthPreset } from 'vite-plugin-image-presets'
import shoji from './plugins/shoji.ts' // → 檢查env vars
// TODO: (1)調整大小 (2)image.svelte
// https://github.com/ElMassimo/vite-plugin-image-presets/blob/main/example/vite.config.ts
// https://github.com/sturdy-dev/codeball-web/blob/main/vite.config.js
// https://github.com/ngalaiko/galaiko.rocks/blob/master/vite.config.js
export const genImageSizePlugin = imagePresets({
thumbnail: widthPreset({
class: 'img thumb',
loading: 'lazy',
widths: [50, 300],
formats: {
webp: { quality: 80 },
},
meta: 'width;height;quality;src',
}),
})
// env
// const isDev = process.env.NODE_ENV !== 'production'
// const isProd = process.env.NODE_ENV === 'production'
const prependScssFiles = [
'@use "src/styles/tokens.scss" as *;',
'@use "src/styles/func.scss" as *;',
'@use "src/styles/mixins" as *;',
].join(' ')
const aliasList = [
{ name: '#components', path: './src/lib/components' },
{ name: '#styles', path: './src/styles' },
{ name: '#utils', path: './src/lib/utils' },
{ name: '#assets', path: './src/assets' },
]
/** @type {import('vite').UserConfig} */
const config = defineConfig({
logLevel: 'warn',
mode: process.env.mode || 'production',
define: {
'process.env.VITE_BUILD_TIME': JSON.stringify(new Date().toISOString()),
'__PROJECT_ROOT__': JSON.stringify(path.dirname(fileURLToPath(import.meta.url))),
},
resolve: {
// alias: { '#': fileURLToPath(new URL('./src', import.meta.url)) }
alias: Object.fromEntries(aliasList.map(alias => [alias.name, path.resolve(alias.path)])),
},
build: {
reportCompressedSize: false,
rollupOptions: {
output: {
manualChunks: undefined,
},
},
},
css: {
preprocessorOptions: {
// scss: {
// includePaths: ['src'],
// prependData: prependScssFiles,
// renderSync: true,
// outputStyle: 'compressed',
// },
postcss: {
configFilePath: './postcss.config.cjs',
},
},
},
esbuild: {
treeShaking: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
},
experimental: {
inspector: {
holdMode: true,
},
},
server: {
host: 'localhost',
port: 9000,
open: true,
strictPort: false,
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
},
hmr: {
overlay: false,
},
},
preview: {
port: 9000,
strictPort: false,
},
optimizeDeps: {
include: [
'@akebifiky/remark-simple-plantuml',
'@rive-app/canvas',
'date-fns',
'hastscript',
'lunarphase-js',
'rehype-slug',
'shiki-twoslash',
],
},
ssr: {
noExternal: ['three'],
},
plugins: [
shoji(),
genImageSizePlugin,
sveltekit(),
],
})
// Add certificate if it's generated
// $ brew install mkcert nss
// $ mkcert -install && cd [project] && mkcert localhost
if (fs.existsSync('localhost-key.pem') && fs.existsSync('localhost.pem')) {
config.server = {
https: {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem'),
},
}
}
export default config
// @links
// https://github.com/dkaoster/www.diplateevo.com/blob/main/svelte.config.js
// https://ics.media/entry/220204/
// https://github.com/tidaltheory/tidaltheory-www/blob/main/lens.config.mjs