mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-24 15:27:43 +01:00
perf: ⚡ Migliorato sistema di import dinamico
- Sostituita import map con import dinamico
This commit is contained in:
parent
c037fc7933
commit
d066ca6989
24
resources/js/app.js
vendored
24
resources/js/app.js
vendored
@ -3,12 +3,9 @@ import '@mdi/font/scss/materialdesignicons.scss';
|
||||
|
||||
import {InertiaProgress} from '@inertiajs/progress';
|
||||
import {createInertiaApp} from '@maicol07/inertia-mithril';
|
||||
import {
|
||||
WAIT_FOREVER,
|
||||
waitUntil
|
||||
} from 'async-wait-until';
|
||||
import $ from 'cash-dom';
|
||||
import m from 'mithril';
|
||||
// noinspection SpellCheckingInspection
|
||||
import redaxios from 'redaxios';
|
||||
|
||||
import {__} from './utils';
|
||||
@ -27,16 +24,21 @@ createInertiaApp({
|
||||
const split = name.split('::');
|
||||
|
||||
if (split.length === 1) {
|
||||
return (await import(`./Views/${name}.jsx`)).default;
|
||||
// Load bundled page
|
||||
const {default: page} = await import(`./Views/${name}.jsx`);
|
||||
return page;
|
||||
}
|
||||
|
||||
const [, page] = split;
|
||||
// Load page from module
|
||||
const [modulePath, page] = split;
|
||||
|
||||
// noinspection JSUnresolvedVariable
|
||||
await waitUntil(() => typeof window.extmodule !== 'undefined', {
|
||||
timeout: WAIT_FOREVER
|
||||
});
|
||||
// noinspection JSUnresolvedVariable
|
||||
return window.extmodule[page];
|
||||
const osmModule = await import(
|
||||
/* @vite-ignore */
|
||||
`${window.import_path}/vendor/${modulePath}/index.js`
|
||||
);
|
||||
|
||||
return osmModule[page];
|
||||
},
|
||||
setup({
|
||||
el,
|
||||
|
@ -30,40 +30,9 @@
|
||||
|
||||
@include('layouts.top-app-bar-menus')
|
||||
|
||||
<!-- Load module outside core -->
|
||||
<script async src="https://unpkg.com/es-module-shims@0.12.8/dist/es-module-shims.js"></script>
|
||||
@php
|
||||
$component = Route::current()->parameter('component');
|
||||
$split1 = explode('::', $component);
|
||||
$path = null;
|
||||
if (count($split1) !== 1) {
|
||||
$split = explode('/', $split1[0]);
|
||||
$vendor = $split[0];
|
||||
$module = $split[1];
|
||||
$path = "vendor/$vendor/$module/index.js";
|
||||
}
|
||||
|
||||
$osm_index = vite_asset('resources/js/index.js');
|
||||
if (!Str::contains($osm_index, config('vite.dev_url'))) {
|
||||
$osm_index = Str::replace('resources/js', '', $osm_index);
|
||||
}
|
||||
@endphp
|
||||
@empty($path)
|
||||
@else
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"external_module": "{{vite_asset($path)}}"
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="module">
|
||||
import * as extModule from 'external_module';
|
||||
|
||||
window.extmodule = extModule;
|
||||
</script>
|
||||
@endempty
|
||||
<script>
|
||||
window.import_path = '{{Str::contains(vite_asset(''), config('vite.dev_url')) ? config('vite.dev_url') : '.'}}';
|
||||
</script>
|
||||
|
||||
@routes
|
||||
@client
|
||||
|
Loading…
x
Reference in New Issue
Block a user