-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
svelte.preprocess has no file path awareness #983
Comments
Decided to investigate further, it seems pretty simple? |
Yeah, should be straightforward. I wonder if we're better off being explicit about the kinds of options we're expecting here, and rather than passing the entire options object around, establish some clear conventions? preprocess(source, {
markup: ({ content, filename }) => {...},
style: ({ content, attributes, filename }) => {...},
script: ({ content, attributes, filename }) => {...},
filename
}); It feels like that would be better in terms of having a clear and consistent approach across build tool integrations and preprocessors, though maybe by proposing a whitelist of 'special' properties I'm not being forward-looking? (I'd envisage that preprocessor plugins would all accept options of their own, so you'd always have to invoke them — |
I don't think being particular about properties is necessarily a problem, it's just limiting how other folks can (ab)use your APIs. That may be attractive or it may not depending on any number of factors. I feel like I'm often trying to do something a bit "odd", so having generic ways to pass things around is usually valuable for me. If you want it to just be a specific property that can be extracted & then passed to the hooks I'm on board w/ that too. |
I reckon we should probably go with just Something else we'll probably want to consider eventually — it'd be cool if preprocessors could return an array of dependencies along with |
Agreed, I worked around that limitation by having |
CASE who? |
Autocorrect on mobile, edited now but it was meant to say "CSS". 😞 |
I may be off topic here, but isn't this what you are after? |
Ha. I thought I was about to learn some new graph terminology! @esarbanis this is about being able to access |
Got this working, eventually. It's a little wild. Example of usage: https://gist.github.com/tivac/0c353a4e0fb32ab05e05a2eac26a1f24 Have to create a function that returns the (This is where a standard API within rollup to add output files would be useful, assuming that So that's gross, but it works! Took our bundle from 72k down to 67k, & the actual user-facing impact would be even better due to a lack of change detection code being parsed/run for our current completely-static CSS objects. Note that this also depends on changes to |
@Rich-Harris would PRs for the changes to |
to add |
I am trying to get the new
svelte.preprocess
functionality working with mymodular-css
project, but currently none of the hooks know anything about the file they're operating on. This is problematic for anyone who wants to do things that could involve external files because it makes file resolution in any sane sort of way impossible.I could solve this with a slightly gnarly closure variable for the case where I'm using
svelte.preprocess
directly, but I don't think that is very likely. I'm usingrollup-plugin-svelte
currently and have no desire to write my own kludgy thing instead if I can avoid it.I have a plan that seems pretty achievable and I'd love to get your thoughts, @Rich-Harris.
I could modify
svelte.preprocess
so that each of the hooks got passed theoptions
object along with thecontent
to manipulate. That would make it possible to pass around more context, like the file path being manipulated. Thenrollup-plugin-svelte
would be modified to pass theid
into the call tosvelte.preprocess()
and anyone who wants to manipulate the sections could do it with enough context to resolve@import
statements or anything else they want.Thoughts? I'm happy to fumble my way through a PR for this, I really want to get
modular-css
working withsvelte.preprocess()
so I can shrink our bundles!The text was updated successfully, but these errors were encountered: