-
Notifications
You must be signed in to change notification settings - Fork 412
Support and document how to publish modules using Linaria to NPM #178
Copy link
Copy link
Open
Labels
cat: documentation 📖Work focused on writing documentationWork focused on writing documentationcat: improve publishing 🚢Issues about improvement of publishing libs with LinariaIssues about improvement of publishing libs with Linariaenhancement: approved ✅Improvement of the current behaviour that has been approvedImprovement of the current behaviour that has been approvedstatus: up for grabs 🙏research is done and issue is ready to be grabbedresearch is done and issue is ready to be grabbed
Description
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.
- It produces vanilla CSS files, which means anyone can consume them
- It doesn't have a runtime overhead, so regardless what solution the user uses for CSS, this is not going to another CSS in JS lib to the mix
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
- Use
single: trueand ask users to take care of loading the CSS file - Use
single: falseand require a bundler like webpack to load the CSS files - Publish the source to npm and ask users to transpile their
node_moduleswith Babel
Blockers
- The inserted imports are absolute paths, which make it impossible to share the stylesheets among different machines
- The class names might not be unique because they are based on developer's folder structure, so if two people named "Dave" have same folder structure, e.g.
Users/Dave/projects/components, but have libraries with different names, the class names might clash
Proposal
- Convert imports paths to be relative to the file, pretty-straightforward (fix: insert relative imports for CSS files and support absolute path in outDir #180)
- It's impossible to generate globally unique names, but we can have some logic so that the hashes include the package name, for example: instead of
src/App.js, we useawesome@version~src/App.jsto generate the hash, whereawesomeis the name of the package andversionis the version of package we read frompackage.jsonif 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
cat: documentation 📖Work focused on writing documentationWork focused on writing documentationcat: improve publishing 🚢Issues about improvement of publishing libs with LinariaIssues about improvement of publishing libs with Linariaenhancement: approved ✅Improvement of the current behaviour that has been approvedImprovement of the current behaviour that has been approvedstatus: up for grabs 🙏research is done and issue is ready to be grabbedresearch is done and issue is ready to be grabbed