-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
104 lines (99 loc) · 2.77 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import copy from 'rollup-plugin-copy';
// Define entry points
const entryPoints = {
'js/form/index': resolve( __dirname, 'assets/js/form/index.ts' ),
'js/registration/index': resolve( __dirname, 'assets/js/registration/index.ts' ),
'js/authentication/index': resolve( __dirname, 'assets/js/authentication/index.ts' ),
'js/admin/index': resolve( __dirname, 'assets/js/admin/index.ts' ),
'css/default-login': resolve( __dirname, 'assets/css/default-login.scss' ),
'css/plugin-settings': resolve( __dirname, 'assets/css/plugin-settings.scss' ),
};
// Load environment variables
const { VITE_WP_PLUGIN_PATH, VITE_DEV_SERVER_PORT, VITE_SITE_URL } = process.env;
// Get the site URL from environment variable or use a default
// This should match your Local by Flywheel site URL
const siteUrl = VITE_SITE_URL || 'https://webauth.local';
export default defineConfig( ( { mode } ) => {
const isProduction = mode === 'production';
return {
base: VITE_WP_PLUGIN_PATH ? `${ VITE_WP_PLUGIN_PATH }dist/` : '/wp-content/plugins/wp-passkeys/dist/',
build: {
outDir: 'dist',
emptyOutDir: true,
manifest: true,
minify: isProduction ? 'terser' : false,
sourcemap: ! isProduction,
cssCodeSplit: true,
rollupOptions: {
input: entryPoints,
output: {
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
assetFileNames: '[name].[ext]',
format: 'es',
},
plugins: [
// Copy static assets
copy( {
targets: [
{ src: 'assets/img/*', dest: 'dist/img' },
],
hook: 'writeBundle',
} ),
],
},
terserOptions: {
compress: {
drop_console: isProduction,
drop_debugger: isProduction,
},
},
},
resolve: {
alias: {
'@types': resolve( __dirname, 'assets/js/types' ),
},
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
quietDeps: true, // Suppress Sass deprecation warnings from dependencies
},
},
},
server: {
// Configure dev server
port: VITE_DEV_SERVER_PORT ? parseInt( VITE_DEV_SERVER_PORT, 10 ) : 3000,
strictPort: true,
// Use proxy to handle HTTPS through Local by Flywheel
proxy: {
// Proxy all requests to the Local by Flywheel site
'/': {
target: siteUrl,
changeOrigin: true,
secure: false,
},
},
hmr: {
host: 'localhost',
protocol: 'ws',
port: VITE_DEV_SERVER_PORT ? parseInt( VITE_DEV_SERVER_PORT, 10 ) : 3000,
overlay: true,
// Force HMR to work with SCSS files
cssCodeSplit: true,
},
watch: {
// Ensure SCSS files are watched
usePolling: true,
interval: 100,
include: [ 'assets/css/**/*.scss' ],
},
},
optimizeDeps: {
include: [ '@simplewebauthn/browser' ],
},
};
} );