-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
79 lines (70 loc) · 2.16 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
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { v4wp } from '@kucrut/vite-for-wp';
import { wp_scripts } from '@kucrut/vite-for-wp/plugins';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import { glob } from 'glob';
import { defineConfig } from 'vite';
import { wordpressPlugin } from './resources/scripts/build/vite-wordpress';
const __dirname = dirname(fileURLToPath(import.meta.url));
// Get all styles and scripts from blocks
const blockStylesEntries = [];
const blocksStyles = glob.sync(
resolve(__dirname, 'resources/blocks/**/style.css'),
);
blocksStyles.forEach((style) => {
blockStylesEntries[style.replace(`${__dirname}/`, '').replace('.css', '')] =
style.replace(`${__dirname}/`, '');
});
const blockScriptsEntries = [];
const blocksScripts = glob.sync(
resolve(__dirname, 'resources/blocks/**/script.ts'),
);
blocksScripts.forEach((js) => {
blockScriptsEntries[js.replace(`${__dirname}/`, '').replace('.ts', '')] =
js.replace(`${__dirname}/`, '');
});
export default defineConfig({
plugins: [
tailwindcss(),
v4wp({
input: {
// Core
coreEditorJs: 'resources/scripts/editor.ts',
coreEditorStyles: 'resources/styles/editor.css',
coreAppStyles: 'resources/styles/app.css',
// Components
sliderJs: 'resources/core-components/slider/slider.script.ts',
sliderStyles: 'resources/core-components/slider/slider.style.css',
// Blocks
...blockStylesEntries,
...blockScriptsEntries,
},
outDir: 'public/build',
}),
// Handle WP external dependencies
wp_scripts(),
react({
jsxRuntime: 'classic',
}),
wordpressPlugin(),
],
optimizeDeps: {
// Fix imports from webpack built libraries
include: ['@10up/block-components'],
},
server: {
cors: true,
},
resolve: {
alias: {
'@scripts': '/resources/scripts',
'@styles': '/resources/styles',
'@fonts': '/resources/fonts',
'@images': '/resources/images',
'@blocks': '/resources/blocks',
'@webentorCore': '/node_modules/webentor-core-js/src',
},
},
});