Replies: 2 comments
-
As a sub-idea of this, Remix could provide more types like a type image to opt-in into build-time image optimization // gives you the hashed URL without any optimization like usual
import heroImage from "~/assets/hero.jpg"
// gives you the hashed URL with optimizations in place
import heroImage from "~/assets/hero.jpg" assert { type: "image" } Using import evaluator attributes it could allow customizations too import heroImage from "~/assets/hero.jpg" assert { type: "image" } with {
quality: 80,
srcSet: [720,1080, 2048],
placeholder: true
}; Another option could be to use this with WebWorkers import worker from "~/workers/foo.js" assert { type: "worker" }
// somewhere client-side
worker.postMessage(value) So Remix could provide different loaders and let developers, using import assertions, specify which want to use on each import. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This have been formalized in #4549 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Right now, the Remix compiler needs to maintain a large list of file extensions to know how to deal with each type of file
remix/packages/remix-dev/compiler/loaders.ts
Lines 4 to 40 in fd00bc6
From what you can see there, files can be
json
(only used for .json files)file
(to get a URL)text
(to get the value as a string)jsx
(to import them as codeI propose using, if possible, import assertions to let users configure that, limited probably to the types
file
andtext
.This should import the file
~/queries/get-user.gql
and give me the content as stringWe can use it to also import more file types, for example a SQL query
Or an example someone brought in the Discord
Or if we want to get a URL import as file:
In this case, we're telling the compiler that the file
~/web-worker.js
should be treated not as a JS module but as a file, so it will move it to the build directory and give us back the hashed URL allowing developer to import JS files that WebWorkers, Service Workers or files they need to pass to a script tag.The whole idea is to let developers import random files and get their content or hashed URL without having Remix to manually add them to the list of loaders and
Beta Was this translation helpful? Give feedback.
All reactions