From 672899af6b1ada76d35d1129680e89afbe6d2c35 Mon Sep 17 00:00:00 2001 From: Olivier Gorzalka Date: Thu, 8 Oct 2026 11:49:47 +0200 Subject: [PATCH 1/2] feat: build with the shared @pollora/vite-config Same build as before: manifests and built files (theme.json included) compared before and after, identical. --- package.json | 2 +- vite.config.js | 157 +++++++++---------------------------------------- 2 files changed, 29 insertions(+), 130 deletions(-) diff --git a/package.json b/package.json index 8acdd14..dfc24ff 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "build": "vite build" }, "devDependencies": { + "@pollora/vite-config": "^1.0.0", "@roots/vite-plugin": "^2.0.0", "@tailwindcss/typography": "^0.5.19", "@tailwindcss/vite": "^4.2.3", @@ -17,7 +18,6 @@ "@wordpress/i18n": "^5.0.0", "alpinejs": "^3.9.1", "axios": "^1.15.1", - "glob": "^11.0.0", "laravel-vite-plugin": "^3.0.1", "swiper": "^11.0.0", "tailwindcss": "^4.2.3", diff --git a/vite.config.js b/vite.config.js index 9468aeb..3ca9e97 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,136 +1,35 @@ -import { defineConfig } from "vite"; -import laravel, { refreshPaths } from 'laravel-vite-plugin'; -import { wordpressPlugin, wordpressThemeJson } from '@roots/vite-plugin'; -import { globSync } from 'glob'; -import path from 'path'; -import tailwindcss from '@tailwindcss/vite'; - -// Détection de l'environnement -const isDocker = process.env.IS_DOCKER || process.env.DOCKER_ENV || process.env.DDEV_PRIMARY_URL; -const port = 5173; -const publicDirectory = "../../public"; -const themeName = path.basename(__dirname); - -const getBaseUrl = () => { - return process.env.APP_URL || process.env.DDEV_PRIMARY_URL || 'http://localhost'; -}; - -const isHttps = getBaseUrl().startsWith('https'); - -const blockEntries = globSync([ - './resources/views/blocks/*/{index,view}.{js,jsx,ts,tsx}', - './resources/views/blocks/*/{editor,style}.css', -]) - .reduce((acc, file) => { - // Keyed by path: blocks sharing a file name never overwrite each other - acc[file.replace(/^\.\//, '').replace(/\.\w+$/, '')] = file; - return acc; - }, {}); -const hasBlocks = Object.keys(blockEntries).length > 0; - -const getDevServerConfig = () => { - const commonConfig = { - server: { - port, - strictPort: true, - cors: { - origin: '*', - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], - credentials: true - }, - } - }; - - if (isDocker) { - return { - server: { - ...commonConfig.server, - host: '0.0.0.0', - origin: `${getBaseUrl()}:${port}`, - hmr: { - protocol: isHttps ? 'wss' : 'ws', - host: new URL(getBaseUrl()).hostname, - } - }, - }; - } - - return { - server: { - ...commonConfig.server, - https: isHttps, - host: isHttps ? new URL(getBaseUrl()).hostname : 'localhost', - hmr: { - protocol: isHttps ? 'wss' : 'ws', - host: new URL(getBaseUrl()).hostname - } - }, - }; -}; - -const getThemeConfig = () => ({ - base: "/build/theme/" + themeName, - input: ["./resources/assets/app.js", ...Object.values(blockEntries)], - publicDirectory, - hotFile: path.join(publicDirectory, `${themeName}.hot`), - buildDirectory: path.join("build", "theme", themeName), - refresh: [ - ...refreshPaths.filter((refreshPath) => refreshPath !== 'resources/views/**'), - 'themes/'+themeName+'/resources/views/**/*.blade.php', - 'resources/views/**/*.blade.php', - ], - assets: [ - 'resources/assets/images/**', - 'resources/assets/fonts/**', - ], -}); +import { defineConfig } from 'vite'; +import pollora from '@pollora/vite-config'; export default defineConfig({ - base: "/build/theme/" + themeName, - build: { - emptyOutDir: false, - }, plugins: [ - tailwindcss(), - laravel(getThemeConfig()), - wordpressThemeJson({ - baseThemeJsonPath: './theme.json', - fontLabels: { - sans: 'Sans Serif', - mono: 'Monospace', - }, - fontSizeLabels: { - xs: 'Extra Small', - sm: 'Small', - base: 'Medium', - lg: 'Large', - xl: 'Extra Large', - '2xl': '2X Large', - '3xl': '3X Large', - '4xl': '4X Large', - '5xl': '5X Large', - }, - borderRadiusLabels: { - xs: 'Extra Small', - sm: 'Small', - md: 'Medium', - lg: 'Large', - xl: 'Extra Large', - '2xl': '2X Large', + pollora({ + type: 'theme', + themeJson: { + fontLabels: { + sans: 'Sans Serif', + mono: 'Monospace', + }, + fontSizeLabels: { + xs: 'Extra Small', + sm: 'Small', + base: 'Medium', + lg: 'Large', + xl: 'Extra Large', + '2xl': '2X Large', + '3xl': '3X Large', + '4xl': '4X Large', + '5xl': '5X Large', + }, + borderRadiusLabels: { + xs: 'Extra Small', + sm: 'Small', + md: 'Medium', + lg: 'Large', + xl: 'Extra Large', + '2xl': '2X Large', + }, }, }), - ...(hasBlocks ? [wordpressPlugin()] : []), - { - name: "blade", - handleHotUpdate({ file, server }) { - if (file.endsWith(".blade.php")) { - server.ws.send({ - type: "full-reload", - path: "*", - }); - } - }, - }, ], - ...getDevServerConfig() }); From f99e3e51d9abd0204a8b9fe612cd1b3526fdb62a Mon Sep 17 00:00:00 2001 From: Olivier Gorzalka Date: Thu, 8 Oct 2026 12:09:38 +0200 Subject: [PATCH 2/2] ci: accept the block entries @pollora/vite-config builds --- .github/workflows/tests.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7519202..ba1d84e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,7 +44,13 @@ jobs: echo "::error file=vite.config.js::resources/views/blocks is missing" exit 1 fi - if ! grep -q 'resources/views/blocks' vite.config.js; then + # @pollora/vite-config globs resources/views/blocks itself, unless told `blocks: false` + if grep -q '@pollora/vite-config' vite.config.js; then + if grep -qE 'blocks:[[:space:]]*false' vite.config.js; then + echo "::error file=vite.config.js::vite.config.js passes blocks: false to @pollora/vite-config, so no block asset is bundled" + exit 1 + fi + elif ! grep -q 'resources/views/blocks' vite.config.js; then echo "::error file=vite.config.js::vite.config.js does not glob resources/views/blocks, so no block asset is bundled" exit 1 fi