Replies: 3 comments 2 replies
-
Ok, my test worked !!! I cannot believe it :-) Here is some info. first of all, I installed react. I changed vite.config.ts:
here is the content of the Assets folder:
In other words I placed the different scripts in their own folders under Assets. In the index.cshtml I placed:
I tested the published version by running the exe and it found the js scripts properly! |
Beta Was this translation helpful? Give feedback.
-
Hi @boggye. Well, you could have one entry point per page if you want, although I would suggest using one entry point per layout. I think it's better to have more than one entry point only when two pages change a lot both visually and behaviorally. For example, in a CMS system, the admin dashboard and the home page usually have different designs and behaviors. Then you would have two entry points, one for each layout. On the other hand, to minimize script loading on pages to include only the React components you're going to use on each page, I think it might be a better approach to use dynamic imports instead, which will split your entry point into chunks. These chunks will be imported and loaded to the page as you call them in your scripts. |
Beta Was this translation helpful? Give feedback.
-
Hi @Eptagone Thanks for the suggestions. I will definitely look into it. The more I think about it, I think you are right - it make sense to have one entry point per layout, which will actually keep things simple. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Hi - I have an MVC application that has many cshtml views. I have a main layout page where I want to use some react components, but I also have other pages where I want to use other components.
From looking at the vite.config.js file of the MVC example, we have just:
input: 'Assets/main.ts',
. According to the vite docs you can have multiple input entries:(this is an example from my tests).
This poses an interesting issue - if a page01 uses a main layout which pulls some react components, then it has its own components, I guess the script for page01 should not include scripts already included by the main layout (such as the react library). Or maybe I am going the wrong way about it, the page itself should take care of loading everything it needs including the stuff that the main layout needs.
How would one separate the scripts? Ideally, under Assets I would have something like this:
I am going to experiment more to see if I can get it to work and I will come back here with more information if I find an acceptable solution.
Just a disclaimer: I am very new to vite, and react, but I have experience with the .net platform. I have to admit that I find vite challenging - there are a lot of moving pieces that have to be placed so the cshtml view can reference them at development time and in the production environment.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions