DEV Community

Cover image for Dataverse Web Resources - Say Goodbye to CRA, Hello to Vite! ๐Ÿš€
Riccardo Gregori
Riccardo Gregori

Posted on

Dataverse Web Resources - Say Goodbye to CRA, Hello to Vite! ๐Ÿš€

If you've been building WebResources for Dataverse using React, TypeScript, and Fluent UI, you've probably already stumbled upon my previous posts on this topic, and probably right now you rely on @_neronotte/cra-template-dataverse-webresources and @_neronotte/cra-template-dataverse-webresources-forms, my scaffolding templates for Create React App (CRA).

Well, times are changing: CRA has officially been deprecated! ๐Ÿ˜ฑ
If you try to start creating a new react app with CRA, since Feb 14th the installer shows you the following deprecation warning:

Deprecation warning from CRA installer

But don't worryโ€”Iโ€™ve got you covered. After some serious hands-on work, Iโ€™ve migrated my templates to Vite, the community-suggested replacement for CRA. Say hello to vite-template-dataverse-webresources! ๐ŸŽ‰

๐Ÿ‘‰ GitHub Repo: https://github.com/neronotte/vite-template-dataverse-webresources

Why Vite? โšก

Vite is faster, leaner, and just better than CRA in so many ways:

  • Instant server startup โฉ
  • Faster hot module replacement ๐Ÿ”ฅ
  • Optimized build process ๐Ÿ—๏ธ
  • Native ESM support ๐Ÿ“ฆ

If you're still on CRA, nowโ€™s the perfect time to migrate!

Whatโ€™s in the Box? ๐Ÿ“ฆ

The repository now contains two branches:

  • ๐ŸŒ Main Branch (for Sitemap & Modal WebResources)
    • Use this template to create WebResources that are accessed from the Dataverse sitemap, or open as modal dialog or side panes in model-driven apps.
  • ๐Ÿ“ Forms Branch (for WebResources inside Forms)
    • Use this template to create WebResources that integrate directly into Dataverse forms, and need to interact with form data and context

How to Get Started ๐Ÿš€

Getting up and running is easier than ever. You can use degit to clone the repo templates. If you don't have it already installed, you can do it via:

npm install -g degit
Enter fullscreen mode Exit fullscreen mode

then just type:

npx degit neronotte/vite-template-dataverse-webresources#main my-webresource
cd my-webresource
npm install
Enter fullscreen mode Exit fullscreen mode

(replace #main with #forms if you want to use the template for form-based WebResources)

And follow the instructions on the README.md file to have everything properly set-up and ready to use. ๐Ÿ’ฅ

To run your WebResource and debug it locally you can simply type:

npm run dev
Enter fullscreen mode Exit fullscreen mode

It will launch Vite local server, tipically on port 5173. You can just open a browser on http://localhost:5173 and you're ready to go!

To build your WebResource in production mode, ready to be deployed in your Dataverse, just type:

npm run build
Enter fullscreen mode Exit fullscreen mode

Then you can use PACX as described here to upload the generated HTML/JS/CSS files into Dataverse.

Migration Made Easy ๐ŸŽฏ

If you've been using CRA for your Dataverse WebResources, moving to Vite is effortless with this template. The structure remains familiar, and the setup process is straightforwardโ€”so you can transition smoothly without hassle.

Check out the repo, give it a try, and let me know if you have any feedback! Contributions are always welcome. ๐Ÿš€๐Ÿ’ก

Happy coding! ๐Ÿ˜ƒ

Top comments (1)

Collapse
 
calechko profile image
Chris Alechko

This was very useful. It helped me conceptually to achieve what I was looking for and the pacx deployment option is fantastic for automation. I was able to do something very similar using parcel + react, then I use Fiddler with auto-responder rules that allows me to live debug as a I develop, then only deploy once I am ready. I was also able to eliminate the need to wire up Javascript events, but still get the same experience of the OnLoad context, and lastly I built a little router that lets me route my web resources to components, so I can deploy the html + js file once, but support as many web resources, forms, etc. as I want to. Let me know if you want to connect to see how I completed this, and thank you again for providing the base and the inspiration! -Chris