-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
72 lines (69 loc) · 1.89 KB
/
vite.config.ts
File metadata and controls
72 lines (69 loc) · 1.89 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import fs from 'fs';
const sourceBanner = '/*! Codeideal Open Fields - Source: https://github.com/novincode/openfields/tree/main/admin/src - Build: pnpm run build */\n';
function bannerPlugin() {
return {
name: 'banner',
writeBundle(_options: any, bundle: Record<string, any>) {
for (const [fileName] of Object.entries(bundle)) {
if (fileName.endsWith('.js')) {
const filePath = path.resolve(__dirname, 'plugin/assets/admin', fileName);
const content = fs.readFileSync(filePath, 'utf-8');
fs.writeFileSync(filePath, sourceBanner + content);
}
}
},
};
}
export default defineConfig({
plugins: [react(), bannerPlugin()],
resolve: {
alias: {
'@': path.resolve(__dirname, './admin/src'),
},
},
build: {
outDir: 'plugin/assets/admin',
emptyOutDir: false, // Don't delete fields.js and fields.css
rollupOptions: {
input: {
admin: path.resolve(__dirname, 'admin/src/main.tsx'),
},
external: ['@wordpress/i18n'],
output: {
format: 'iife',
globals: {
'@wordpress/i18n': 'wp.i18n',
},
entryFileNames: 'js/[name].js',
chunkFileNames: 'js/[name].[hash].js',
assetFileNames: (assetInfo) => {
if (assetInfo.name?.endsWith('.css')) {
return 'css/[name][extname]';
}
return 'assets/[name][extname]';
},
},
},
},
server: {
port: 3000,
strictPort: true,
proxy: {
'/wp-json': {
target: 'http://localhost:8888',
changeOrigin: true,
},
'/wp-admin': {
target: 'http://localhost:8888',
changeOrigin: true,
},
'/wp-content': {
target: 'http://localhost:8888',
changeOrigin: true,
},
},
},
});