-
-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic import/require in resolveComponent/resolve function using modules? #957
Comments
Have you imported "path" into your webpack.mix? Like: |
Of course. |
@maxonfjvipon Not 100% sure but it might be related to the webpack's dynamic imports being limited to specific directory only, meaning that you will be able to only bundle files in a single directory you provide in your dynamic expression. I had the same problem with my project where I've tried to generate separate chunks for every page to avoid loading whole app in single JS file as it is treated as performance issue. I wasn't able to do that with standard dynamic import because I have my pages separated into multiple directories. I ended up using Here is how I've configured my entrypoint file: const app = document.getElementById("app") as HTMLElement;
const init = JSON.parse(app.dataset.page as string);
const context = require.context("resources/js/Pages", true, /\.tsx$/, "lazy");
const resolver = (name: string) => context("resources/js/Pages/" + name + ".tsx").then((module: any) => {
const page = module.default;
// ... some default layouts staff here
return page;
});
ReactDOM.render(<InertiaApp initialPage={init} resolveComponent={resolver} initialComponent={LoadingScreen}/>, app); As you can see I declare files context which scans for all *.tsx files recursively inside my I think it's worth to try it that way. |
Thanks for your answer. Now I don't have any errors, just I warning. I also tried to move |
I also check this issue and it seems there is no way to call That's sad, but, we don't have a choise) |
@maxonfjvipon It probably doesn't work because you're trying to use const context = require.context('../../Modules', true, /\.js$/, 'lazy'); If you have other JS files in your modules which you don't want to include there a third argument of that That big list of files you get now when webpack builds, are actually your chunks, so every page will be generated as separate output, and will only be loaded when it's needed. |
@maxonfjvipon Just in case, make sure to console.log context and check generated map with files paths. In my case I always get absolute paths in map, no matter if I use an absolute or relative path in var map = {
"./Article/Index.tsx": [
"./resources/js/Pages/Web/Article/Index.tsx",
"resources_js_Pages_Web_Article_Index_tsx"
],
"./Article/Show.tsx": [
"./resources/js/Pages/Web/Article/Show.tsx",
"resources_js_Pages_Web_Article_Show_tsx"
],
"./Blog/Index.tsx": [
"./resources/js/Pages/Web/Blog/Index.tsx",
"resources_js_Pages_Web_Blog_Index_tsx"
],
"./Blog/Show.tsx": [
"./resources/js/Pages/Web/Blog/Show.tsx",
"resources_js_Pages_Web_Blog_Show_tsx"
],
"./Contact/Index.tsx": [
"./resources/js/Pages/Web/Contact/Index.tsx",
"resources_js_Pages_Web_Contact_Index_tsx"
],
"./Error.tsx": [
"./resources/js/Pages/Web/Error.tsx",
"resources_js_Pages_Web_Error_tsx"
],
"./Homepage/Index.tsx": [
"./resources/js/Pages/Web/Homepage/Index.tsx",
"resources_js_Pages_Web_Homepage_Index_tsx"
],
"resources/js/Pages/Web/Article/Index.tsx": [
"./resources/js/Pages/Web/Article/Index.tsx",
"resources_js_Pages_Web_Article_Index_tsx"
],
"resources/js/Pages/Web/Article/Show.tsx": [
"./resources/js/Pages/Web/Article/Show.tsx",
"resources_js_Pages_Web_Article_Show_tsx"
],
"resources/js/Pages/Web/Blog/Index.tsx": [
"./resources/js/Pages/Web/Blog/Index.tsx",
"resources_js_Pages_Web_Blog_Index_tsx"
],
"resources/js/Pages/Web/Blog/Show.tsx": [
"./resources/js/Pages/Web/Blog/Show.tsx",
"resources_js_Pages_Web_Blog_Show_tsx"
],
"resources/js/Pages/Web/Contact/Index.tsx": [
"./resources/js/Pages/Web/Contact/Index.tsx",
"resources_js_Pages_Web_Contact_Index_tsx"
],
"resources/js/Pages/Web/Error.tsx": [
"./resources/js/Pages/Web/Error.tsx",
"resources_js_Pages_Web_Error_tsx"
],
"resources/js/Pages/Web/Homepage/Index.tsx": [
"./resources/js/Pages/Web/Homepage/Index.tsx",
"resources_js_Pages_Web_Homepage_Index_tsx"
]
}; What you actually provide later, using Hope it helps. |
@interviadmin @rafalkrawiec |
@maxonfjvipon Seems like your if statement is wrong, as it never gets to that context() call. I think there should be |
@rafalkrawiec @interviadmin I did not realize before that first argument in |
this don't seem to work in 0.11.0 version
|
Versions:
@inertiajs/inertia
version: 0.10.1@inertiajs/inertia-react
version: 0.7.1Describe the problem:
Hello everyone. I use InertiaJS with Laravel. Also I use nWidart/laravel-modules. I want to render JS files from my modules dynamically. They are in Modules/Module-name/Resources/assets/js.
This is my controller
My webpack.mix
This is my app.js
In this case I go many webpack errors like:
I also tried with
CreateInertiaApp
andrequired
functions - the same resultBut if I use static path to module files like:
~/AdminPanel/Resources/assets/js/${parts[0]}
then there are no errors and everything works fine. But that means I should describe all my modules and static paths to their js files in app.js. I would want to escape this.I also checked this issue and this one but unsuccessfully... Someone has the same errors, someone has it works fine
Thanks
The text was updated successfully, but these errors were encountered: