-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
105 lines (94 loc) · 3.31 KB
/
vite.config.ts
File metadata and controls
105 lines (94 loc) · 3.31 KB
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
import { defineConfig } from 'vite';
import type { PluginOption } from 'vite';
import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import linkCssTreeShaking from './plugin/vite-plugin-link-css-tree-shaking';
import tamperBannerAndCssInjection from './plugin/vite-plugin-tamper-banner-and-css-injection';
import externalGlobals from 'rollup-plugin-external-globals';
import { visualizer } from 'rollup-plugin-visualizer';
import { bannerConfig, globalConfig } from './config/getParameters';
export default defineConfig(({ command, mode }) => {
const isBuild = command === 'build';
const primitive = mode === 'primitive';
const minify = mode === 'minify';
const analyze = mode === 'analyze';
const global = mode === 'global';
const buildPlugins: PluginOption[] = isBuild
? [
linkCssTreeShaking({
// Provide the file entry manually, or provide the path to the component file
// manualEntry: 'path/to/your/custom.css',
componentsFilesPath: globalConfig.map(config => config.componentsFilesPaths),
replaceVariableDeclarations: true,
}),
tamperBannerAndCssInjection({
beautifulCss: true,
bannerConfig,
globalImport: {
importByCDN: global,
importConfig: globalConfig,
},
}),
].concat(
analyze
? [
visualizer({
emitFile: true,
filename: 'stats.html',
}),
]
: [],
)
: [];
return {
css: {
preprocessorOptions: {
less: { math: 'parens-division' },
sass: { api: 'modern' },
},
},
server: {
port: 5267,
open: true,
proxy: {
// '/picture': {
// target: 'https://dailybing.com/api/v1',
// changeOrigin: true,
// secure: true,
// rewrite: path => path.replace(/^\/picture/, ''),
// },
},
},
build: {
target: 'esnext',
outDir: 'release',
assetsInlineLimit: 16384,
chunkSizeWarningLimit: 2048,
minify: 'terser',
terserOptions: {
compress: !primitive,
mangle: !primitive,
format: { beautify: !minify },
},
rollupOptions: {
input: './src/index.ts',
output: { entryFileNames: `${bannerConfig.name}.user.js` },
//Only Vue is supported in framework, or other 3rd-party libraries that support UMD or IIFE export
external: global ? ['vue', 'pinia'] : [],
plugins: global
? [
externalGlobals({
vue: 'Vue',
pinia: 'Pinia',
}),
]
: [],
},
},
plugins: [
svelte({
preprocess: vitePreprocess()
}),
...buildPlugins,
],
};
});