Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"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",
"@wordpress/blocks": "^14.0.0",
"@wordpress/components": "^29.0.0",
"@wordpress/element": "^6.0.0",
"@wordpress/i18n": "^5.0.0",
"glob": "^11.0.0",
"laravel-vite-plugin": "^3.0.1",
"tailwindcss": "^4.2.3",
"vite": "^8.0.9"
Expand Down
107 changes: 3 additions & 104 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,6 @@
import { defineConfig } from "vite";
import laravel, { refreshPaths } from 'laravel-vite-plugin';
import { wordpressPlugin } from '@roots/vite-plugin';
import { globSync } from 'glob';
import path from 'path';
import tailwindcss from '@tailwindcss/vite';

// Environment detection
const isDocker = process.env.IS_DOCKER || process.env.DOCKER_ENV || process.env.DDEV_PRIMARY_URL;
const port = 5174; // Different port for plugins (5173 for themes)
const publicDirectory = "../../../../public";
const pluginName = 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 getPluginConfig = () => ({
base: "/build/plugin/" + pluginName,
input: ["./resources/assets/app.js", ...Object.values(blockEntries)],
publicDirectory,
hotFile: path.join(publicDirectory, `${pluginName}.hot`),
buildDirectory: path.join("build", "plugin", pluginName),
refresh: [
...refreshPaths.filter((refreshPath) => refreshPath !== 'resources/views/**'),
'public/content/plugins/'+pluginName+'/resources/views/**/*.blade.php',
'resources/views/**/*.blade.php',
'public/content/plugins/'+pluginName+'/app/**/*.php',
],
});
import { defineConfig } from 'vite';
import pollora from '@pollora/vite-config';

export default defineConfig({
base: "/build/plugin/" + pluginName,
build: {
emptyOutDir: false,
},
plugins: [
tailwindcss(),
laravel(getPluginConfig()),
...(hasBlocks ? [wordpressPlugin()] : []),
{
name: "blade",
handleHotUpdate({ file, server }) {
if (file.endsWith(".blade.php") || file.endsWith(".php")) {
server.ws.send({
type: "full-reload",
path: "*",
});
}
},
},
],
...getDevServerConfig()
plugins: [pollora({ type: 'plugin' })],
});
Loading