Replies: 3 comments
-
Does this also works for imports from node_modules? ie, would it solve #1909 ? |
Beta Was this translation helpful? Give feedback.
-
This would be useful for exploring libraries that use proprietary file types such as Spline.design (uses .splinecode). Interested in seeing this come to life. |
Beta Was this translation helpful? Give feedback.
-
I'm +1 to this approach as well, import assertions feel like the "right" approach here, in the meantime I've proposed a temporary solution for loading arbitrary file types using the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Let developers use import assertions (Stage 3 feature) to customize what file loaders to use in order to let them use more than just the predefined list of supported files
Background
There have been many case where people ended up sending a PR to add a new file extension to the list of loaders here
remix/packages/remix-dev/compiler/loaders.ts
Lines 4 to 40 in fd00bc6
I think Remix could use the import assertions to let developer tell Remix how to load those imported files.
Use Case
API/Examples
Let's imagine a developer wants to use GraphQL, but because queries are long it wants to move them to a
.gql
or.graphql
file, after importing them the developer wants to get a string with the value of the query, using import assertions it could doThe magic part is the
assert { type: "text" }
which is how the developer is telling the Remix compiler "treat this file as a plain text file".The same developer could do the same later to import an SQL query too
Now, imagine you're coding a WebWorker, you need the path to the JS file so you can initialize it like
new WebWorker("file.js")
, if you try to import it normally Remix could consider any JS file a JS module but here the developer want the hashed URL to that file, so the developer could use thetype: "file"
to tell Remix to treat this import as a file and gives you back a hashed URL, as with images or fonts.Provide build-time optimizations
Remix could also provide some pre-defined loaders that optimize the imported file, in prior version Remix used to optimize images at build-time using the
img:
prefix on the import pathWith import assertions and image could be imported as
The import type
image
can serve as a way for the developers to ask Remix to optimize this image on build-time, because doing this will make build slower the default should be to simply hash the file nameAdding to this using import evaluator attributes it should be possible to let developers customize the optimizations
And following this idea, Remix could provide more loader types for developers to use, for example a worker type for WebWorkers
Beta Was this translation helpful? Give feedback.
All reactions