create-wordpress-theme-ts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ import { defineConfig, loadEnv } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import eslint from 'vite-plugin-eslint';
4
+ import { viteStaticCopy } from 'vite-plugin-static-copy';
5
+ import zipPack from 'vite-plugin-zip-pack';
6
+
7
+ /**
8
+ * Vite Configuration for WordPress React Theme
9
+ */
10
+ export default defineConfig(({ mode }) => {
11
+ // Load env file based on `mode` (.env, .env.development, .env.production)
12
+ const env = loadEnv(mode, process.cwd(), '');
13
+
14
+ return {
15
+ // ========================================
16
+ // PLUGINS
17
+ // ========================================
18
+ plugins: [
19
+ // React support with Fast Refresh for HMR
20
+ react(),
21
+
22
+ // ESLint integration - shows lint errors in terminal during dev
23
+ eslint({
24
+ failOnError: false,
25
+ failOnWarning: false,
26
+ }),
27
+
28
+ // Copy static files to dist
29
+ // - PHP files for WordPress theme
30
+ // - WordPress theme style.css (with required header)
31
+ // - Images from public folder
32
+ viteStaticCopy({
33
+ targets: [
34
+ {
35
+ src: 'php/*',
36
+ dest: '',
37
+ },
38
+ {
39
+ src: 'public/style.css',
40
+ dest: '',
41
+ },
42
+ {
43
+ src: 'public/images/*',
44
+ dest: 'images',
45
+ },
46
+ ],
47
+ }),
48
+
49
+ // Create WordPress theme zip after build
50
+ zipPack({
51
+ inDir: 'dist',
52
+ outDir: 'dist',
53
+ outFileName: 'wordpress-custom-theme.zip',
54
+ }),
55
+ ],
56
+
57
+ // Static assets directory (favicon, images, etc.)
58
+ publicDir: 'public',
59
+
60
+ // ========================================
61
+ // BUILD OPTIONS
62
+ // ========================================
63
+ build: {
64
+ outDir: 'dist',
65
+ emptyOutDir: true,
66
+
67
+ // Source maps: inline for dev debugging, disabled for production
68
+ sourcemap: mode === 'development' ? 'inline' : false,
69
+
70
+ // Target modern browsers
71
+ target: 'esnext',
72
+
73
+ // Rollup output configuration
74
+ rollupOptions: {
75
+ output: {
76
+ // Fixed filenames for WordPress compatibility (no hashes)
77
+ // WordPress functions.php expects bundle.js and bundle.css
78
+ // style.css is reserved for WordPress theme header
79
+ entryFileNames: 'bundle.js',
80
+ chunkFileNames: '[name].js',
81
+ assetFileNames: (assetInfo) => {
82
+ if (assetInfo.name?.endsWith('.css')) {
83
+ return 'bundle.css';
84
+ }
85
+ return 'assets/[name][extname]';
86
+ },
87
+ },
88
+ },
89
+ },
90
+
91
+ // ========================================
92
+ // DEV SERVER
93
+ // ========================================
94
+ server: {
95
+ port: 8080,
96
+ open: true, // Auto-open browser on start
97
+ },
98
+
99
+ // Preview server (for testing production builds locally)
100
+ preview: {
101
+ port: 8080,
102
+ },
103
+
104
+ // Polyfill process.env for libraries that expect Node.js environment
105
+ define: {
106
+ 'process.env': {},
107
+ },
108
+ };
109
+ });