Last active
May 30, 2023 22:49
-
-
Save innocenzi/cb7e539426b6526a9ae79145d71a98d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path' | |
import vue from '@vitejs/plugin-vue' | |
import icons from 'vite-plugin-svg-icons' | |
import inspect from 'vite-plugin-inspect' | |
import tailwindcss from 'tailwindcss' | |
import autoprefixer from 'autoprefixer' | |
import createDebugger from 'debug' | |
import { defineConfig } from 'laravel-vite' | |
export default defineConfig() | |
.withPlugin(inspect) | |
.withPlugin(icons({ iconDirs: [path.resolve(process.cwd(), 'resources/icons')] }) as any) | |
.withPlugin(() => ({ | |
name: 'vite:inertia:layout', | |
transform: (code: string, id: string) => { | |
if (!/<template +layout *= *['"](\w+)['"] *>/.test(code)) { | |
return | |
} | |
const layouts = '@/views/layouts/' | |
const debug = createDebugger('vite:inertia:layout') | |
const isTypeScript = /lang=['"]ts['"]/.test(code) | |
return code.replace(/<template +layout *= *['"](\w+)['"] *>/, (_, layoutName) => { | |
debug(`Using custom Inertia layout (${layoutName}) for SFC: ${id}`) | |
return ` | |
<script${isTypeScript ? ' lang="ts"' : ''}> | |
import layout from '${layouts}${layoutName}.vue' | |
export default { layout } | |
</script> | |
<template> | |
` | |
}) | |
}, | |
})) | |
.withPlugin(vue) | |
.withPostCSS([tailwindcss, autoprefixer]) | |
.withCertificates() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment