how do i pass data from themes.php in laravel config folder to vite.config.js? i want to pass the vite buld_directory to the vite.config.js so it knows which directory to use during build process based on selected theme. the error i'm getting is: No loader is configured for ".php" files: config/themes.php when i run npm run assets
// a section of the package.json file
"scripts": {
"dev": "vite",
"build": "vite build",
"assets": "vite build --watch"
},
<?php
// themes.php config file
return [
'theme' => 'shop', // selected theme
'themes' => [
'shop' => [
'name' => 'Default Shop Theme',
'assets_path' => 'themes/shop/assets',
'views_path' => 'resources/views/shop',
'vite' => [
'hot_file' => 'shop-vite.hot',
'build_directory' => 'themes/shop/build',
'package_assets_directory' => 'resources/shop',
],
],
'mart' => [
'name' => 'Mart Shop Theme',
'assets_path' => 'themes/mart/assets',
'views_path' => 'resources/views/mart',
'vite' => [
'hot_file' => 'mart-vite.hot',
'build_directory' => 'themes/mart/build',
'package_assets_directory' => 'resources/mart',
],
],
],
];
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { resolve } from 'path';
import { default as tailwindcss } from 'tailwindcss';
import { default as autoprefixer } from 'autoprefixer';
// Load theme configuration
const themeConfig = require('./config/themes.php');
const themeName = themeConfig.theme || 'shop'; // Use the default theme if not specified
const theme = themeConfig.themes[themeName] || {};
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
css: {
postcss: {
plugins: [
tailwindcss(resolve('tailwind.config.js')),
autoprefixer,
],
},
},
build: {
outDir: theme.vite && theme.vite.build_directory ? `public/${theme.vite.build_directory}` : 'public/build',
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
var info = assetInfo.name.split(".");
var extType = info[info.length - 1];
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
extType = "imgs";
} else if (/woff|woff2/.test(extType)) {
extType = "css/fonts";
}
return `assets/${extType}/[name]-[hash][extname]`;
},
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
},
},
},
});