mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-24 23:37:51 +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 {InertiaProgress} from '@inertiajs/progress';
|
||||||
import {createInertiaApp} from '@maicol07/inertia-mithril';
|
import {createInertiaApp} from '@maicol07/inertia-mithril';
|
||||||
import {
|
|
||||||
WAIT_FOREVER,
|
|
||||||
waitUntil
|
|
||||||
} from 'async-wait-until';
|
|
||||||
import $ from 'cash-dom';
|
import $ from 'cash-dom';
|
||||||
import m from 'mithril';
|
import m from 'mithril';
|
||||||
|
// noinspection SpellCheckingInspection
|
||||||
import redaxios from 'redaxios';
|
import redaxios from 'redaxios';
|
||||||
|
|
||||||
import {__} from './utils';
|
import {__} from './utils';
|
||||||
@ -27,16 +24,21 @@ createInertiaApp({
|
|||||||
const split = name.split('::');
|
const split = name.split('::');
|
||||||
|
|
||||||
if (split.length === 1) {
|
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
|
// noinspection JSUnresolvedVariable
|
||||||
await waitUntil(() => typeof window.extmodule !== 'undefined', {
|
const osmModule = await import(
|
||||||
timeout: WAIT_FOREVER
|
/* @vite-ignore */
|
||||||
});
|
`${window.import_path}/vendor/${modulePath}/index.js`
|
||||||
// noinspection JSUnresolvedVariable
|
);
|
||||||
return window.extmodule[page];
|
|
||||||
|
return osmModule[page];
|
||||||
},
|
},
|
||||||
setup({
|
setup({
|
||||||
el,
|
el,
|
||||||
|
@ -30,40 +30,9 @@
|
|||||||
|
|
||||||
@include('layouts.top-app-bar-menus')
|
@include('layouts.top-app-bar-menus')
|
||||||
|
|
||||||
<!-- Load module outside core -->
|
<script>
|
||||||
<script async src="https://unpkg.com/es-module-shims@0.12.8/dist/es-module-shims.js"></script>
|
window.import_path = '{{Str::contains(vite_asset(''), config('vite.dev_url')) ? config('vite.dev_url') : '.'}}';
|
||||||
@php
|
</script>
|
||||||
$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
|
|
||||||
|
|
||||||
@routes
|
@routes
|
||||||
@client
|
@client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user