# Vite build breaks mechanism to provide extra resources for the editor

**URL:** <https://discourse.nodered.org/t/vite-build-breaks-mechanism-to-provide-extra-resources-for-the-editor/91007>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [15 September 2024 17:10 UTC](https://discourse.nodered.org/t/vite-build-breaks-mechanism-to-provide-extra-resources-for-the-editor/91007 "2024-09-15T17:10:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [15 September 2024 17:10 UTC](https://discourse.nodered.org/t/vite-build-breaks-mechanism-to-provide-extra-resources-for-the-editor/91007/1 "2024-09-15T17:10:05Z")

</div>

When building a widget for Dashboard-2, `vite` places the resulting file into the `/resources` folder:

> <https://github.com/FlowFuse/node-red-dashboard-2-ui-example/blob/a5f443e290a4d453dac46e6ad9b9845dcc5958d9/vite.config.js#L26-L27>

Unfortunately, as it's [documentation](https://vitejs.dev/config/build-options.html#build-emptyoutdir) states,

> by default, Vite will empty the outDir on build if it is inside project root.

This is unfortunate, as it deletes as well all (other) files existing in `/resources`, thus breaking the mechanism to provide additional files to [load into the editor as extra resources](https://nodered.org/docs/creating-nodes/resources).

I've created a [PR](https://github.com/FlowFuse/node-red-dashboard-2-ui-example/pull/19) to fix this issue:

- Rather than building directly into `/resources`, `vite` shall build into `ui/dist` directory.
- The resulting file will then be copied into `/resources`.
- The operation will be performed by `vite-plugin-static-copy`, added as `dev-dependency`.
- To [compensate for an error when trying to require an ESM only module](https://vitejs.dev/guide/troubleshooting#this-package-is-esm-only), `vite.config.js` has to be renamed to `vite.config.mjs`.
- Took the opportunity to fix as well the repo path in `package.json`, still pointing to a `flowforge` repo, non-existing.

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [16 September 2024 08:14 UTC](https://discourse.nodered.org/t/vite-build-breaks-mechanism-to-provide-extra-resources-for-the-editor/91007/2 "2024-09-16T08:14:20Z")

</div>

Thanks for much for the detailed report and PR. Had missed entirely the fact that the `resources` folder would be emptied by `vite`.

Have commented on the PR with some thoughts.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 October 2024 08:14 UTC](https://discourse.nodered.org/t/vite-build-breaks-mechanism-to-provide-extra-resources-for-the-editor/91007/3 "2024-10-16T08:14:58Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
