mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 13:32:43 +01:00
add support for extension vite plugin loading, add vue setup hook for extensions
This commit is contained in:
@@ -18,11 +18,14 @@ createInertiaApp({
|
||||
import.meta.glob<DefineComponent>('./Pages/**/*.vue')
|
||||
),
|
||||
setup({ el, App, props, plugin }) {
|
||||
createApp({ render: () => h(App, props) })
|
||||
.use(plugin)
|
||||
.use(pinia)
|
||||
.use(ZiggyVue)
|
||||
.mount(el);
|
||||
const app = createApp({ render: () => h(App, props) });
|
||||
|
||||
// currently only one vue app setup hook is supported
|
||||
if (window.vueAppSetupHook) {
|
||||
window.vueAppSetupHook(app);
|
||||
}
|
||||
|
||||
app.use(plugin).use(pinia).use(ZiggyVue).mount(el);
|
||||
},
|
||||
|
||||
progress: {
|
||||
|
||||
2
resources/js/types/global.d.ts
vendored
2
resources/js/types/global.d.ts
vendored
@@ -2,11 +2,13 @@ import { PageProps as InertiaPageProps } from '@inertiajs/core';
|
||||
import { AxiosInstance } from 'axios';
|
||||
import ziggyRoute from 'ziggy-js';
|
||||
import { PageProps as AppPageProps } from './';
|
||||
import type { App } from 'vue';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
axios: AxiosInstance;
|
||||
initialDataLoaded: boolean;
|
||||
vueAppSetupHook?: (app: App) => void;
|
||||
}
|
||||
|
||||
let route: typeof ziggyRoute;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
<!-- Scripts -->
|
||||
@routes
|
||||
@vite(['resources/js/app.ts', "resources/js/Pages/{$page['component']}.vue"])
|
||||
@vite(\Nwidart\Modules\Module::getAssets())
|
||||
@inertiaHead
|
||||
</head>
|
||||
<body class="font-sans antialiased">
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
async function collectModuleAssetsPaths(paths, modulesPath) {
|
||||
async function collectModuleAssetsPaths(modulesPath) {
|
||||
return await getExportedModulesArrayAttributes(modulesPath, 'paths');
|
||||
}
|
||||
|
||||
async function collectModulePlugins(modulesPath) {
|
||||
return await getExportedModulesArrayAttributes(modulesPath, 'plugins');
|
||||
}
|
||||
|
||||
async function getExportedModulesArrayAttributes(modulesPath, attribute) {
|
||||
const result = [];
|
||||
modulesPath = path.join(__dirname, modulesPath);
|
||||
|
||||
const moduleStatusesPath = path.join(__dirname, 'modules_statuses.json');
|
||||
@@ -37,10 +46,10 @@ async function collectModuleAssetsPaths(paths, modulesPath) {
|
||||
const moduleConfig = await import(viteConfigPath);
|
||||
|
||||
if (
|
||||
moduleConfig.paths &&
|
||||
Array.isArray(moduleConfig.paths)
|
||||
moduleConfig[attribute] &&
|
||||
Array.isArray(moduleConfig[attribute])
|
||||
) {
|
||||
paths.push(...moduleConfig.paths);
|
||||
result.push(...moduleConfig[attribute]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +60,7 @@ async function collectModuleAssetsPaths(paths, modulesPath) {
|
||||
);
|
||||
}
|
||||
|
||||
return paths;
|
||||
return result;
|
||||
}
|
||||
|
||||
export default collectModuleAssetsPaths;
|
||||
export { collectModuleAssetsPaths, collectModulePlugins };
|
||||
|
||||
@@ -2,33 +2,49 @@ import { defineConfig } from 'vite';
|
||||
import laravel from 'laravel-vite-plugin';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import checker from 'vite-plugin-checker';
|
||||
import {
|
||||
collectModuleAssetsPaths,
|
||||
collectModulePlugins,
|
||||
} from './vite-module-loader.js';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
laravel({
|
||||
input: 'resources/js/app.ts',
|
||||
refresh: true,
|
||||
}),
|
||||
vue({
|
||||
template: {
|
||||
transformAssetUrls: {
|
||||
base: null,
|
||||
includeAbsolute: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
checker({
|
||||
// e.g. use TypeScript check
|
||||
typescript: true,
|
||||
vueTsc: true,
|
||||
lintCommand: 'eslint "./**/*.{ts,vue}"',
|
||||
}),
|
||||
],
|
||||
server: {
|
||||
host: true,
|
||||
hmr: {
|
||||
host: process.env.VITE_HOST_NAME,
|
||||
clientPort: 80,
|
||||
async function getConfig() {
|
||||
const paths = ['resources/js/app.ts'];
|
||||
const modulePaths = await collectModuleAssetsPaths('extensions');
|
||||
const additionalPlugins = await collectModulePlugins('extensions');
|
||||
|
||||
return defineConfig({
|
||||
build: {
|
||||
sourcemap: true, // Source map generation must be turned on
|
||||
},
|
||||
},
|
||||
});
|
||||
plugins: [
|
||||
laravel({
|
||||
input: [...paths, ...modulePaths],
|
||||
refresh: true,
|
||||
}),
|
||||
vue({
|
||||
template: {
|
||||
transformAssetUrls: {
|
||||
base: null,
|
||||
includeAbsolute: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
checker({
|
||||
// e.g. use TypeScript check
|
||||
typescript: true,
|
||||
vueTsc: true,
|
||||
lintCommand: 'eslint "./**/*.{ts,vue}"',
|
||||
}),
|
||||
...additionalPlugins,
|
||||
],
|
||||
server: {
|
||||
host: true,
|
||||
hmr: {
|
||||
host: process.env.VITE_HOST_NAME,
|
||||
clientPort: 80,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default getConfig();
|
||||
|
||||
Reference in New Issue
Block a user