create-wordpress-theme-ts 1.0.0 → 1.0.2

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.
@@ -1,109 +1,67 @@
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
- });
1
+ import react from '@vitejs/plugin-react';
2
+ import { defineConfig } from 'vite';
3
+ import { viteStaticCopy } from 'vite-plugin-static-copy';
4
+ import zipPack from 'vite-plugin-zip-pack';
5
+ import eslint from 'vite-plugin-eslint2';
6
+ import { resolve } from 'path';
7
+
8
+ // Generate timestamp suffix (YYYYMMDDHHmmss)
9
+ const timestamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14);
10
+
11
+ export default defineConfig(({ mode }) => ({
12
+ plugins: [
13
+ react(),
14
+ eslint({
15
+ emitWarning: true,
16
+ emitError: true,
17
+ }),
18
+ // Copy PHP files, style.css and favicon to dist root
19
+ viteStaticCopy({
20
+ targets: [
21
+ { src: 'php/*', dest: '.' },
22
+ { src: 'public/style.css', dest: '.' },
23
+ { src: 'public/assets/icons/favicon.ico', dest: '.' },
24
+ ],
25
+ }),
26
+ // Create ZIP file of the dist folder
27
+ zipPack({
28
+ outDir: 'dist',
29
+ outFileName: `wordpress-custom-theme-${timestamp}.zip`,
30
+ }),
31
+ ],
32
+ root: '.', // Root directory where index.html is located
33
+ publicDir: false, // Disable Vite's default public dir copying since we're using viteStaticCopy
34
+ build: {
35
+ outDir: 'dist',
36
+ emptyOutDir: true,
37
+ sourcemap: mode === 'production', // Generate source maps for production
38
+ cssCodeSplit: false, // Extract all CSS into a single file
39
+ rollupOptions: {
40
+ input: resolve(__dirname, 'index.html'),
41
+ output: {
42
+ format: 'iife', // Output as IIFE format for browser compatibility (no ES module exports)
43
+ entryFileNames: 'bundle.js', // Name the main bundle 'bundle.js' since required by WordPress themes
44
+ chunkFileNames: '[name].js', // For any code-split chunks (if any)
45
+ // For assets like images, fonts
46
+ assetFileNames: (assetInfo) => {
47
+ // Output bundled CSS as bundle.css (separate from WordPress theme's style.css)
48
+ const name = assetInfo.names?.[0] || '';
49
+ if (name.endsWith('.css')) {
50
+ return 'bundle.css';
51
+ }
52
+ return 'assets/[name][extname]';
53
+ },
54
+ },
55
+ },
56
+ minify: mode === 'production' ? 'terser' : false, // Minify in production
57
+ },
58
+ // Development server configuration
59
+ server: {
60
+ port: 8080,
61
+ open: true,
62
+ },
63
+ // Module resolution configuration
64
+ resolve: {
65
+ extensions: ['.tsx', '.ts', '.js'],
66
+ },
67
+ }));
@@ -1,2 +0,0 @@
1
- node_modules/
2
- dist/
@@ -1,34 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2021": true,
5
- "node": true
6
- },
7
- "extends": [
8
- "eslint:recommended",
9
- "plugin:react/recommended",
10
- "plugin:react-hooks/recommended",
11
- "plugin:@typescript-eslint/recommended",
12
- "plugin:prettier/recommended"
13
- ],
14
- "parser": "@typescript-eslint/parser",
15
- "parserOptions": {
16
- "ecmaFeatures": {
17
- "jsx": true
18
- },
19
- "ecmaVersion": "latest",
20
- "sourceType": "module"
21
- },
22
- "plugins": ["react", "@typescript-eslint", "prettier"],
23
- "rules": {
24
- "react/react-in-jsx-scope": "off",
25
- "react/no-unescaped-entities": "off",
26
- "prettier/prettier": "error",
27
- "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
28
- },
29
- "settings": {
30
- "react": {
31
- "version": "detect"
32
- }
33
- }
34
- }
@@ -1,7 +0,0 @@
1
- /// <reference types="vite/client" />
2
-
3
- // Type declaration for vite-plugin-eslint (no @types package available)
4
- declare module 'vite-plugin-eslint' {
5
- import { Plugin } from 'vite';
6
- export default function eslint(options?: Record<string, unknown>): Plugin;
7
- }