-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
vite.config.js
126 lines (124 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
// vite.config.js
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import vue from '@vitejs/plugin-vue2';
import path from 'path';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import visualizer from 'rollup-plugin-visualizer';
import { VuetifyResolver } from 'unplugin-vue-components/resolvers';
import createComponentsPlugin from 'unplugin-vue-components/vite';
import { defineConfig, loadEnv } from 'vite';
import mkcert from 'vite-plugin-mkcert';
import { VitePWA } from 'vite-plugin-pwa';
/**
* Replace env variables in index.html
* @see https://github.com/vitejs/vite/issues/3105#issuecomment-939703781
* @see https://vitejs.dev/guide/api-plugin.html#transformindexhtml
*/
function htmlPlugin(env) {
return {
name: 'html-transform',
transformIndexHtml: {
enforce: 'pre',
transform: (html) => html.replace(/%(.*?)%/g, (match, p1) => env[p1] ?? match),
},
};
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
define: {
global: 'globalThis',
},
server: {
https: false,
},
open: true,
port: 3001,
plugins: [
visualizer(),
vue(),
createComponentsPlugin({
resolvers: [
VuetifyResolver(),
],
}),
VitePWA({
registerType: 'autoUpdate',
strategies: 'injectManifest',
srcDir: 'src',
filename: 'service-worker.js',
includeAssets: ['img/icons/favicon.ico', 'img/icons/apple-touch-icon-180x180.png', 'img/icons/safari-pinned-tab.svg'],
manifest: {
name: 'Div3',
short_name: 'Div3',
description: 'Interact with the Casper Blockchain',
theme_color: '#00126b',
icons: [
{
src: 'img/icons/pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'img/icons/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'img/icons/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
}),
mkcert(),
htmlPlugin(loadEnv(mode, '.')),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'readable-stream': 'vite-compatible-readable-stream',
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},
// Enable esbuild polyfill plugins
plugins: [
NodeModulesPolyfillPlugin(),
NodeGlobalsPolyfillPlugin({
buffer: true,
}),
{
name: 'fix-node-globals-polyfill', // FIXME https://github.com/remorses/esbuild-plugins/issues/24
setup(build) {
build.onResolve(
{ filter: /(_virtual-process-polyfill_|_buffer)\.js/ },
({ path }) => ({ path }),
);
},
},
],
},
},
build: {
rollupOptions: {
plugins: [nodePolyfills()],
},
commonjsOptions: {
transformMixedEsModules: true,
},
sourcemap: true,
},
css: {
preprocessorOptions: {
sass: { additionalData: '@import "@/scss/variables.scss"\n' },
},
},
}));