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

Bundle passing the source code #82

Closed
oscarotero opened this issue Feb 14, 2022 · 8 comments
Closed

Bundle passing the source code #82

oscarotero opened this issue Feb 14, 2022 · 8 comments

Comments

@oscarotero
Copy link

Hi, thanks for this awesome project.

transform allows to set the source code but bundle only works by setting a filename. I need to bundle a css code passing the source code. Do you have plans to implementing that?

@oscarotero oscarotero changed the title Bundle code Bundle passing the source code Feb 14, 2022
@devongovett
Copy link
Member

It's not possible because we need to read the dependencies (i.e. @import) from the file system. I thought about a way for the JS API to pass a function callback to retrieve the contents of dependencies when needed, but this would significantly slow things down. What's your use case for this?

@oscarotero
Copy link
Author

My use case is this plugin for Lume (a static site generator for Deno): https://github.com/lumeland/lume/blob/master/plugins/parcel_css.ts

The plugin gets the content of the css files, process the code and update the content. I don't mind parcel-css reads the dependencies from the file system, but I'd like to set the code of the main file (the entry point).

There are other similar plugins for Lume that works in the same way:

In these two cases, the plugin reads the content of the loaded files, process the code and inlines the imported dependencies from the file system. The dependencies are resolved related to the main file path or providing a list of paths.

@devongovett
Copy link
Member

Well another problem for Deno is that the WASM build doesn't have bundle at all because WASM doesn't have filesystem access. I'm not sure if there is a way to solve that.

@oscarotero
Copy link
Author

Ah, I didn't know that.
I'm not familiarized with Rust + WASM, but for SASS, I'm using denosass that is WASM and has access to the file system, I don't know if this helps.

Your idea of providing a JS API to read files and retrieve the content looks good too, and maybe it's the most flexible.

Another idea is providing a set of sources, in the same way Deno.emit() does (https://doc.deno.land/deno/unstable/~/Deno.EmitOptions) but this does not fix the entire problem because you need to know the sources before.

@yisar
Copy link

yisar commented Feb 22, 2022

I think this is a very common requirement, or you can provide a rust plugin to do this.
Because I think for parcel-css, adding as many fetures as possible is a good direction.
Especially some fetures that are not standard but very commonly used, such as @importrpx

@petergoes
Copy link

I would like this feature as well. My use case: bundle all css files in a design system dynamically.
I have a folder of components where each component has its own folder with a dedicated css file. In a build script I collect all css file paths. I do something like this (the array is generated with fs)

const csscode = [
  'components/button/button.css',
  'components/header/header.css'
  ...
]
.map(path => `@import './${path}';`)
.join('\n')

This gives me a 'virtual' css file with only import statements that I want to bundle.

This way:

  • team mates do not forget to add css files
  • The file structure is the single source of truth just like the routes in the routes folder (like remix_run, nuxt and next)

@devongovett
Copy link
Member

Should be possible in the next version by implementing a custom resolver: #263. See the bundleAsync example in the readme: https://github.com/parcel-bundler/parcel-css#from-node

@oscarotero
Copy link
Author

Oh, that's awesome!
I'm looking forward to the next version.
Thank you

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

No branches or pull requests

4 participants