-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import JSON as module #386
Comments
because deno doesn't support |
but in your case i guess you can add a json file loader like: import type { Plugin } from 'aleph/types.d.ts'
export default <Plugin>{
name: 'json-loader',
setup: aleph => {
aleph.onLoad(/\.json$/i, async ({ specifier }) => {
const { content } = await aleph.fetchModule(specifier)
return {
code: `export default ` + new TextDecoder().decode(content)
}
})
}
} |
anyway, i added a |
Thanks. Would you be interested in a YAML loader as well? I can send a PR. |
cool, can you please create a deno module? like https://github.com/ije/aleph-plugin-windicss, then add it to https://github.com/alephjs/alephjs.org/blob/master/pages/docs/plugins/community-plugins.md, if you're interested, thanks @akaFTS |
In fact, |
That's expected because Deno doesn't have a builtin JSON importer You can use index.tsx // @ts-ignore
import json from "~/assets/test.json"
export default function Home() {
const [count, isSyncing, increase, decrease] = useCounter()
const version = useDeno(() => Deno.version.deno)
console.log(json)
... Don't forget to install the plugin aleph.config.ts import type { Config } from 'aleph/types'
import json from "aleph/plugins/json.ts"
export default <Config>{
plugins: [json()]
} |
But I assume Deno also does not have a built-in CSS importer and still deno-ts does not complain when you import those in Aleph. Is there no way to customize it and whitelist some extensions? Also as Aleph evolves and other third-party loaders are added (i.e. GraphQL or YAML), they will also face the same issue and adding @ts-ignore to everything is very cumbersome. |
I think that may be because the CSS import doesn't have a name:
While the JSON does have a name:
|
Deno now supports importing JSON as module. https://deno.com/blog/v1.17#import-assertions-and-json-modules Dynamic importing works with Aleph, but local and remote seem to not.
|
Importing JSON files as modules causes a deno-ts error:
Seems to be just a matter of adding the above flag to Aleph's tsconfig.
The text was updated successfully, but these errors were encountered: