-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
vite.e2e.config.js
96 lines (94 loc) · 2.48 KB
/
vite.e2e.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
// 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 { VuetifyResolver } from 'unplugin-vue-components/resolvers';
import createComponentsPlugin from 'unplugin-vue-components/vite';
import { defineConfig, loadEnv } from 'vite';
import istanbul from 'vite-plugin-istanbul';
/**
* 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: [
vue(),
createComponentsPlugin({
resolvers: [
VuetifyResolver(),
],
}),
istanbul({
include: 'src/*',
exclude: ['node_modules', 'tests/'],
extension: ['.js', '.ts', '.vue'],
forceBuildInstrument: true,
}),
htmlPlugin(loadEnv(mode, '.')),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
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' },
},
},
}));