S
SolidJS•4mo ago
Bersaelor

importing static assets (telling vinxi/vite about stuff other then png's)

Every other month, I feel like i'm facing this again. How to import static assets in solidjs? The docs https://docs.solidjs.com/solid-start/building-your-application/static-assets say:
Vite provides a way to import assets directly into your Solid components:
import logo from "./solid.png";
import logo from "./solid.png";
If I try the same with other stuff like *.svg or *.txt the import fails. I did have a an older solidjs project where I could do
import sprite from '../../assets/img/sprite.svg';
import sprite from '../../assets/img/sprite.svg';
In the old project I did this via
// vite.config.mts

import solidSvg from 'vite-plugin-solid-svg'

export default defineConfig({
plugins: [suidPlugin(), solidPlugin(), solidSvg({ defaultAsComponent: false })],
...
})
// vite.config.mts

import solidSvg from 'vite-plugin-solid-svg'

export default defineConfig({
plugins: [suidPlugin(), solidPlugin(), solidSvg({ defaultAsComponent: false })],
...
})
Is there a way we can still do this with solidjs/start? Since we don't have a vite.config anymore?
9 Replies
Brendonovich
Brendonovich•4mo ago
For .txt try adding ?raw to the path For the svg plugin add it to vite.plugins in your config
Bersaelor
BersaelorOP•4mo ago
thank you for reminding me of ?raw, it doesn't seem to work though
No description
Brendonovich
Brendonovich•4mo ago
It should work at runtime, you might need to add your own types
Bersaelor
BersaelorOP•4mo ago
ah, it seems it may work after all, just typescript throwing errors I see the solidSvg you would put in the vite section of
// app.config.ts

export default defineConfig({
ssr: false,
server: {
static: true,
preset: "static"
},
vite: {
plugins: [suidPlugin() as PluginOption],
// app.config.ts

export default defineConfig({
ssr: false,
server: {
static: true,
preset: "static"
},
vite: {
plugins: [suidPlugin() as PluginOption],
?
Brendonovich
Brendonovich•4mo ago
Yeah
intelligent-worker-probe
I put all my static files in the public/ folder and reference them using absolut paths (folder = public/imgs/img.png, link = /imgs/img.png). I wonder if it is better or worse vs using the static import feature from vite?
Bersaelor
BersaelorOP•4mo ago
yeah, I used to do most imports via vite but now I'm also mostly using the public folder..
Tjerk
Tjerk•4mo ago
Hey there 👋 How did you solve this yet ? May I know ? I'm facing the issue that if i use vite-plugin-solid-svg my app breaks with
No description
Bersaelor
BersaelorOP•4mo ago
try with the above comment on ?raw maybe that works typescript will still complain but in my build it worked
Want results from more Discord servers?
Add your server