This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
forked from gothinkster/realworld-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
86 lines (84 loc) · 2.18 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
import ts from '@rollup/plugin-typescript';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';
import { injectHtml, minifyHtml } from 'vite-plugin-html';
export default defineConfig(({ command }) => {
const configDir = dirname(fileURLToPath(import.meta.url));
const srcDir = resolve(configDir, 'src');
const pagesDir = resolve(srcDir, 'pages');
const rev = command === 'build' ? Date.now().toString(32) : '';
const scriptPath =
command === 'build'
? function (path) {
return `${this.base}${path}`;
}
: function (path) {
return `${path}`;
};
return {
root: pagesDir,
base: './',
plugins: [
minifyHtml({
removeAttributeQuotes: false,
removeEmptyAttributes: false,
}),
injectHtml({
injectData: { rev },
injectOptions: {
root: resolve(srcDir, 'template'),
context: {
base: null,
setBase(base) {
this.base = base;
},
scriptPath,
},
},
}),
{
...ts(),
apply: 'build',
},
],
esbuild: command !== 'build',
css: {
preprocessorOptions: {
scss: {
quietDeps: true,
},
},
},
build: {
outDir: '../../dist',
chunkSizeWarningLimit: 1024 * 1024,
emptyOutDir: true,
rollupOptions: {
input: {
home: resolve(pagesDir, 'index.html'),
article: resolve(pagesDir, 'article', 'index.html'),
editor: resolve(pagesDir, 'editor', 'index.html'),
login: resolve(pagesDir, 'login', 'index.html'),
profile: resolve(pagesDir, 'profile', 'index.html'),
register: resolve(pagesDir, 'register', 'index.html'),
settings: resolve(pagesDir, 'settings', 'index.html'),
},
},
sourcemap: true,
minify: 'terser',
terserOptions: {
ecma: 2019,
module: true,
toplevel: true,
output: {
ascii_only: true,
comments: false,
},
},
},
server: {
port: 4200,
},
};
});