From 682d8b764b8ac84564c502271648a45d9570420d Mon Sep 17 00:00:00 2001 From: Olivier Gorzalka Date: Thu, 8 Oct 2026 11:46:17 +0200 Subject: [PATCH] feat: build with the shared @pollora/vite-config Same build and hot file as before: manifests and built files compared before and after, identical. --- package.json | 2 +- vite.config.js | 155 +++++++++---------------------------------------- 2 files changed, 28 insertions(+), 129 deletions(-) diff --git a/package.json b/package.json index 0b71803..7fcd73e 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/vite": "^4.2.3", "@wordpress/block-editor": "^14.0.0", @@ -15,7 +16,6 @@ "@wordpress/element": "^6.0.0", "@wordpress/i18n": "^5.0.0", "axios": "^1.15.1", - "glob": "^11.0.0", "laravel-vite-plugin": "^3.0.1", "tailwindcss": "^4.2.3", "vite": "^8.0.9" diff --git a/vite.config.js b/vite.config.js index 286f2aa..367c90e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,135 +1,34 @@ -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', - // Inter needs its @font-face, which only theme.json can declare - disableTailwindFonts: true, - 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', - '6xl': '6X Large', - '7xl': '7X Large', - }, - borderRadiusLabels: { - sm: 'Small', - md: 'Medium', - lg: 'Large', - xl: 'Extra Large', - '2xl': '2X Large', + pollora({ + type: 'theme', + themeJson: { + // Inter needs its @font-face, which only theme.json can declare + disableTailwindFonts: true, + 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', + '6xl': '6X Large', + '7xl': '7X Large', + }, + borderRadiusLabels: { + 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() });