Using Svelte and vite with the right

Using Svelte and vite with the right configuration, anything you put in the ./public folder gets copied to the ./dist root when my Svelte code is built. I use that for a version.json file and static images. I'm guessing that there is something similar for any other framework. What framework are you using? I don't recommend doing that for .js or .ts that your Functions import though. Rather, import those in your Function source. When you do that, the Pages build process incorporates them into the renamed bundles and rewrites the imports appropriately so you never need to know the names.
14 Replies
Larry
LarryOP3y ago
For vite, here is where public directory behavior is explained. Aparently its the default so no need to even adjust the vite config. https://vitejs.dev/guide/assets.html#the-public-directory
Vite
Next Generation Frontend Tooling
Larry
LarryOP3y ago
It looks like esbuild requires a plugin: https://www.npmjs.com/package/esbuild-plugin-public-directory
npm
esbuild-plugin-public-directory
Static assets directory for esbuild pipeline. Latest version: 0.0.5, last published: a year ago. Start using esbuild-plugin-public-directory in your project by running npm i esbuild-plugin-public-directory. There are no other projects in the npm registry using esbuild-plugin-public-directory.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Larry
LarryOP3y ago
What framework and build system are you using?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Larry
LarryOP3y ago
You should be able to control what gets bundled/renamed and what doesn't with that configuration
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Larry
LarryOP3y ago
That's why they are getting renamed. I'm suggesting that you don't import images in your source code (file load) if you want them to be accessible on the internet without a name change. Rather put them in a public folder, use the esbuild-plugin-public-directory and load them from your HTML with a relative url.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Larry
LarryOP3y ago
Maybe esbuild has that natively now like vite does?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Larry
LarryOP3y ago
npm
esbuild-plugin-copy
ESBuild plugin for assets copy.. Latest version: 2.1.0, last published: 5 hours ago. Start using esbuild-plugin-copy in your project by running npm i esbuild-plugin-copy. There are 6 other projects in the npm registry using esbuild-plugin-copy.
Larry
LarryOP3y ago
npm
esbuild-copy-static-files
An esbuild plugin to copy static files that changed from a source directory to a destination directory. Latest version: 0.1.0, last published: a year ago. Start using esbuild-copy-static-files in your project by running npm i esbuild-copy-static-files. There are 4 other projects in the npm registry using esbuild-copy-static-files.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?