-
Notifications
You must be signed in to change notification settings - Fork 414
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
Support and document how to publish modules using Linaria to NPM #178
Comments
FWIW I'm just going to chime in here and challenge this statement:
That is why we even started thinking about making a CSS-in-JS library, which ended in styled-components. We made ElementalUI (which is on npm), but users would have to use webpack and configure it exactly right with the less and css loader so they could use our components, which was a pain. Instead, styled-components lets you publish components and your users don't have to care about how exactly it is styled: they just import it and are ready to go! If they wanna override it, just add a I don't think that assumption ("It generates CSS files so it's great for npm libs!") is true at all, in fact I think it hurts the usability. |
I think In addition to this, there's also the question if multiple CSS in JS libs going to conflict with each other. I have no idea, but it doesn't seem far-fetched. Even if we solve these issues somehow, for people who do server rendering, they have to configure it to generate CSS for each of the CSS in JS libraries used by their dependencies, which is far more worse than configuring their bundler once. And I'm not sure how it will work if the library you depend upon uses a different version of the same CSS in JS library that you use in your app/from a different dependency. When those libraries upgrade/change their dependency on the CSS in JS library, you also have to update your server rendering code.
I'm not sure how will it work. Won't they have to worry about insertion order? i.e. whatever styling solutions they use, they need to make sure that their CSS gets injected after the library injects its CSS. Which might be tricky. No doubt vanilla CSS files are not fully automatic (they are in parcel though) and hence not a great DX, but they avoid all of the above issues. The configuration is one-time and they provide a better UX overall. It's certainly not perfect, but it's the best we have currently. |
I see where you're coming from but we're working on all of those DX issues with https://github.com/cssinjs/istf-spec and @kitten's github.com/kitten/sweetsour, so interop will soon be the standard for CSS-in-JS libs! CSS files ain't changing anytime soon 😉 Anyways, let's agree to disagree, just wanted to chime in with those thoughts. |
I don't think there's anything to disagree here. These are not opinions, but problems which prevent using CSS in JS library. ISTF is great, and I hope it'll solve most of these issues. But to do that, all CSS in JS libraries need to adopt that. What you're saying is ideal, but not practical right now. It'll happen, but in future. And until that happens, vanilla CSS files are the best we have. |
@satya164 To be fair, not all CSS-in-JS libraries need to adopt ISTF or even the connected pipeline. The important part is that a diverse amount of libraries that might or might not form a majority adpot it. Btw it'd be great to talk about how we can proceed with Sweetsour/ISTF. I'm planning to use it for React Native first to test out its constraints and practicality. |
That's exactly where we disagree! For our needs, a shared component library that's meant to be used by any developer who can run I'm not saying That's why I said that the statement above doesn't ring true for my use case at all:
YMMV of course and you're free to say whatever the hell you want, all I'm trying to get across is that that sentence doesn't make any sense to me after I spent two years trying to get rid of vanilla CSS files in my npm packages 😉 |
HMU! You know where to find me :D |
Any news on this?can i publish a lib in es module format just transpiling with babel? |
@satya164 thanks |
@satya164 We will release a stable version of Material-UI v4 in the next few weeks. I want to prepare for v5. We have recently made a developer survey. Aside from people asking for more components and better documentation (something we can fix between v4 and v5), a lot of people are asking for a better customization story, faster components, and a smaller bundle size. If only we can figure a great integration with npm, something that made Material-UI move to CSS-in-JS two years ago. Back at the time, CSS-modules support was hard to configure. |
@oliviertassinari that sounds great. I think it'll be good to prioritize a workflow for publishing in the next few months. I'm currently a bit busy due to conf, but I'll get back to it this soon. |
Closes callstack#299. See also callstack#208, callstack#178
Closes callstack#299. See also callstack#208, callstack#178
Closes callstack#299. See also callstack#208, callstack#178
new classPrefix option Closes callstack#299. See also callstack#208, callstack#178
new classPrefix option Closes callstack#299. See also callstack#208, callstack#178
Just checking to see if there has been any movement on this? I want to create a library of components, and want to know the best way to ensure that consumers only bundle the CSS they need based on the components they've imported. I'm not familiar with Linaria internals, but I'm available for help. |
For anyone who stumbles upon this - here's a brief explanation of all the 3 approaches that @satya164 has mentioned. I was testing it with a UI module which is compiled with babel and uses Typescript and an application which is compiled via Webpack. Approach 1
Notes: Therefore, the command to extract the css looks like this: Caveats: This is not a problem for a small lib, but might be crucial for a big lib of components with hundreds of kilobytes of styles combined. And if you need to Approach 2
Notes: This command will go trough all the Caveats: And the question of how to rebuild the css on file changes still remains. Approach 3
Notes:
Caveats: Then, you'll need to remember to whitelist your library in your webpack and linaria configs. This is not a problem for an internal library, but most likely isn't an option for a public one. |
Background
Linaria is probably the best option to choose among CSS in JS libraries if you are making a component library which you want to publish on NPM.
Today I was trying to publish one of my libraries to NPM which uses Linaria but hit a couple of roadblocks. I hope we can address them.
Approaches
single: true
and ask users to take care of loading the CSS filesingle: false
and require a bundler like webpack to load the CSS filesnode_modules
with BabelBlockers
Users/Dave/projects/components
, but have libraries with different names, the class names might clashProposal
src/App.js
, we useawesome@version~src/App.js
to generate the hash, whereawesome
is the name of the package andversion
is the version of package we read frompackage.json
if it exists, this assumes package names are globally unique. This won't work properly in some scenarios where the styles changed but version number didn't (e.g. installing from git), but it's impossible/extremely hard to do it.Currently, I only need the first one, which should be easy to fix. Appreciate your thoughts.
We also need to document the process of publishing libraries using Linaria to NPM.
The text was updated successfully, but these errors were encountered: