Skip to content
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

WIP - Feat/cli #263

Closed
wants to merge 1 commit into from
Closed

WIP - Feat/cli #263

wants to merge 1 commit into from

Conversation

kaisermann
Copy link
Member

@kaisermann kaisermann commented Oct 5, 2020

Closes #256, #255

Related to: sveltejs/component-template#31 and sveltejs/component-template#8

Opening it as a draft and with no implementation. I'm currently studying the available routes we can take here.

@lukeed
Copy link
Member

lukeed commented Oct 5, 2020

Anything I can help with?

@kaisermann
Copy link
Member Author

@lukeed 🤔 We need to decide what route we should take here. Initially, I was thinking of a very simple CLI that would just preprocess something(s) from --src and output it(them) to --output

$ svelte-preprocess --src src/*.svelte --out dist/

This can be enough for some (most?) cases, but as @dummdidumm noted here, a component can import some, i.e ts module and that obviously wouldn't work from the consumer perspective. Bundling/transpiling these modules don't seem to be the correct way forward to me. Maybe it's just a matter of limiting the scope of what the CLI does.

@kaisermann kaisermann added enhancement New feature or request help wanted Extra attention is needed labels Oct 6, 2020
@lukeed
Copy link
Member

lukeed commented Oct 6, 2020

I would 100% just worry about compiling standalone files. I'm pretty sure the old svelte CLI did this too.
Otherwise, yeah, you definitely encroach on being a full bundler/Rollup wrapper.

If output is targeting ESM, then it's easy to position this as a "prepare your component for bundling" step, since the output is pure JS, CSS, HTML

@kaisermann
Copy link
Member Author

@lukeed I like the idea of positioning the CLI as a bundling "preparation" step, sparing us from dealing with all the minutia of js bundling. However, if we follow this path we should create at least some examples, one simple and another a bit more complex. Maybe the component-template can be used as the example itself, not sure.

Anyways, do you (or anyone else) have thoughts about the CLI API? For now, I was thinking of:

--input | --src - required
Glob(?) of svelte files to be preprocessed

--output - required
Output directory of preprocessed components.
I thought of following the same file structure found in --input, but if the components reside in an src/components, how could one make the components be output to the root of a dist/ directory?

--config - optional
Path to a svelte.config.js. Defaults to process.cwd()/svelte.config.js

@firefish5000
Copy link

Exert of relative code from @tdi/svcli for reference. https://gist.github.com/firefish5000/372ec181a5c47ac5190358639182310f
There is not to much special going on compared to the component-template or the code I stole from here somewhere. It also copies files based off of a glob (which is not necessary by any means). But if this only deals with svelte files we need to be sure to mention how to fix *.js imports (along with custom imports which need their own preprocessors).

Note the main thing it adds that I think is necessary is an extensions field which allows custom extensions like .svx. A input glob would work just as well.

I am also of the opinion that this should only deal with svelte files (ideally with customizable extensions) as anything more than that quickly turns it into a task runner like gulp.

@kaisermann kaisermann closed this Nov 7, 2020
@kaisermann kaisermann deleted the branch master November 7, 2020 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI for preprocessing svelte files
3 participants