Skip to content

Conversation

@dominikg
Copy link
Member

@dominikg dominikg commented Nov 29, 2022

add support for ?raw and ?direct import queries.

fixes #341

HERE BE DRAGONS

The features described here are not meant to be used in regular libraries or end-user applications.
They can be useful for frameworks, documentation sites or in special situations, but you are responsible for applying them correctly.

Proceed with caution!

raw

//get .svelte file content as a string
import content from 'File.svelte?raw';

//get output of svelte.preprocess as {code, map, dependencies}
import preprocessed from 'File.svelte?raw&svelte&type=preprocessed';

//get output of svelte.compile js as {code, map, dependencies}
import script from 'File.svelte?raw&svelte&type=script';

//get output of svelte.compile css as {code, map }
import style from 'File.svelte?raw&svelte&type=style';

//get output of svelte.compile as {source, compiled:{js,css,preprocessed,dependencies,ast}}
import all from 'File.svelte?raw&svelte&type=all';

direct

<!-- load and execute component script -->
<script type="application/javascript" src="File.svelte?direct&svelte&type=script&lang.js" />
<!-- embed component style as css -->
<link rel="stylesheet" type="text/css" href="File.svelte?direct&svelte&type=style&lang.css" />

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. For ?raw with &type etc, I think we should rename ?raw to something else as Vite defines it as something that returns a string. Right now it returns an object with code and map where they can't be treeshaken if you use code only.

This could be done as another PR though as it's experimental.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed exports 🚀

@dominikg dominikg merged commit 1c780ce into main Dec 2, 2022
@dominikg dominikg deleted the feat/support-additional-queries branch December 2, 2022 16:30
@github-actions github-actions bot mentioned this pull request Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the direct query param

3 participants