-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
105 lines (92 loc) · 2.76 KB
/
vite.config.ts
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 vue from '@vitejs/plugin-vue';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Components from 'unplugin-vue-components/vite';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import { readFileSync } from 'fs';
// https://vitejs.dev/config/
export default defineConfig(() => {
return {
server: {
logLevel: 'info',
// middlewareMode: 'ssr',
https: {
key: readFileSync('./.cert/key.pem'),
cert: readFileSync('./.cert/cert.pem'),
},
port: 3333,
hmr: {
host: 'localhost',
port: 3333,
clientPort: 3333
},
strictPort: true,
host: true,
base: '/fm/',
proxy: {
'https://localhost:3333': 'https://localhost:3333'
},
},
plugins: [
Components({
resolvers: [ NaiveUiResolver() ]
}),
vue(),
{
// Hard hack plugin
// Adds local base url to all paths
// Need when main js file used outside test server
name: 'asset-base-url',
enforce: 'post',
transform: (code) => {
const port = '3333';
code = code.replace(
/(from |import\()(["'`])(\/src|~?@|\/@fs\/@)\/(.*?)\.(svg|png|mp3|mp4|eot|woff|ttf|json)/g,
`$1$2http://localhost:${port}/src/$4.$5?import=`);
code = code.replace(/(?<!local)(\/src|~?@|\/@fs\/@)\/(.*?)\.(svg|png|mp3|mp4|eot|woff|ttf|json)/g,
`http://localhost:${port}/src/$2.$3`);
code = code.replace(/'\/node_modules\//g, `'http://localhost:${port}/node_modules/`);
code = code.replace(/"\/node_modules\//g, `"http://localhost:${port}/node_modules/`);
code = code.replace(/(axios\.get\(['"`])\/(.*)(.json)/gm, `$1http://localhost:${port}/$2$3`);
// console.log(code);
return {
code,
map: null,
};
},
},
],
build: {
// lib: {
// entry: path.resolve(__dirname, 'src/main.ts'),
// name: 'MyLib',
// fileName: (format) => `vufman.${format}.js`
// },
rollupOptions: {
output: {
// file: 'bundle.js',
format: 'iife',
name: 'Vufman',
},
// // make sure to externalize deps that shouldn't be bundled
// // into your library
// external: ['vue'],
// output: {
// // Provide global variables to use in the UMD build
// // for externalized deps
// globals: {
// vue: 'Vue'
// }
// }
},
},
resolve: {
alias: [
{ find: '@', replacement: '/src' },
]
},
};
});