All Projects β†’ kentcdodds β†’ Css In Js Precompiler

kentcdodds / Css In Js Precompiler

Licence: mit
WORK IN PROGRESS: Precompiles CSS-in-JS objects to CSS strings

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Css In Js Precompiler

Compiled
A familiar and performant compile time CSS-in-JS library for React.
Stars: ✭ 1,235 (+1639.44%)
Mutual labels:  babel, css-in-js
Next Shopify Storefront
πŸ› A real-world Shopping Cart built with TypeScript, NextJS, React, Redux, Apollo Client, Shopify Storefront GraphQL API, ... and Material UI.
Stars: ✭ 317 (+346.48%)
Mutual labels:  babel, css-in-js
Xwind
Tailwind CSS as a templating language in JS and CSS-in-JS
Stars: ✭ 249 (+250.7%)
Mutual labels:  babel, css-in-js
Twin.macro
πŸ¦Ήβ€β™‚οΈ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, stitches and goober) at build time.
Stars: ✭ 5,137 (+7135.21%)
Mutual labels:  babel, css-in-js
Babel Plugin Tailwind Components
Use Tailwind with any CSS-in-JS library
Stars: ✭ 320 (+350.7%)
Mutual labels:  babel, css-in-js
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-43.66%)
Mutual labels:  babel, css-in-js
Cabana React
A design system built especially for both Sketch and React. πŸ’Žβš›οΈ
Stars: ✭ 58 (-18.31%)
Mutual labels:  css-in-js
Rosebox
CSS in Typescript
Stars: ✭ 62 (-12.68%)
Mutual labels:  css-in-js
.dot Org Files
Dotfiles, Emacs + Org-mode with babel and Literate programming.
Stars: ✭ 57 (-19.72%)
Mutual labels:  babel
Babel Plugin Css Prop
Babel plugin to transpile `css` prop to a styled component. (Experimental)
Stars: ✭ 56 (-21.13%)
Mutual labels:  babel
Eleventy Webpack
A barebone Eleventy and Webpack boilerplate 🎈
Stars: ✭ 68 (-4.23%)
Mutual labels:  babel
Vue
Stars: ✭ 65 (-8.45%)
Mutual labels:  babel
Babel Plugin Proxy
Use ES6 proxies today!
Stars: ✭ 61 (-14.08%)
Mutual labels:  babel
Simple Universal React Redux
The simplest possible Async Universal React & Redux Boilerplate app, that works on both Mac and Windows
Stars: ✭ 58 (-18.31%)
Mutual labels:  babel
Sowing Machine
🌱A React UI toolchain & JSX alternative
Stars: ✭ 64 (-9.86%)
Mutual labels:  babel
Envs
Component development environments for the Bit community
Stars: ✭ 58 (-18.31%)
Mutual labels:  babel
Starter React Flux
Generate your React PWA project with TypeScript or JavaScript
Stars: ✭ 65 (-8.45%)
Mutual labels:  babel
Tinker.macro
Evaluate Laravel code at build-time, via Laravel Tinker
Stars: ✭ 56 (-21.13%)
Mutual labels:  babel
Css In Js Utils
Useful utility functions for CSS in JS solutions
Stars: ✭ 61 (-14.08%)
Mutual labels:  css-in-js
Astexplorer.app
https://astexplorer.net with ES Modules support and Hot Reloading
Stars: ✭ 65 (-8.45%)
Mutual labels:  babel

css-in-js-precompiler

Precompiles static CSS-in-JS objects to CSS strings

CURRENTLY A WORK IN PROGRESS

The problem

You love the benefits of CSS-in-JS, but don't love some of the performance characteristics and trade-offs you have to make with regards to not using actual CSS files.

This solution

This module takes in your source code and gives you back the source code with the literal CSS-in-JS objects swapped for class names as well as the generated CSS. You can then use that to create a css file and deploy that.

It's still pretty early stages

Installation

This is not yet published. But you can install it anyway with:

npm install kentcdodds/css-in-js-precompiler
cd node_modules/css-in-js-precompiler
npm install
npm start build

And you should be able to use it now :)

Usage

This is still under development so the API and assumptions are going to change. But right now, we're naΓ―vely assuming you're using glamorous. But this solution will be modified to work with any CSS-in-JS library you're using.

const precompileCSSInJS = require('css-in-js-precompiler')
const options = {
  sources: [
    {
      code: `import glamorous from 'glamorous';\nglamorous.div({fontSize: 23})`,
      filename: '/some/path.js',
      babelOptions: {/* optional. Shallowly merges with the default babelOptions */}
    },
  ],
}

const result = precompileCSSInJS(options)
result.transformed[0].code === `import glamorous from 'glamorous';\nglamorous.div("css-my79es");`
result.transformed[0].map === '<the code source map>'
result.css === '.css-my79es,[data-css-my79es]{font-size:23px;}'

options

sources

This is an array of SourceObjects which will be used to determine what source to precompile and how. Here are the available properties on these objects:

code

This is the source code to actually precompile. If this is not provided, then the code will be derived from the filename.

filename

This is a string path to the filename. If the code is not provided, this will be used to read the file. If this is not provided, then you will be unable to handle importing dynamic values from other files.

babelOptions

This is the same thing you would pass to babel.transform if you were calling it yourself. Read more here. This will be shallowly merged with the default babelOptions. Currently (2017-05-03) the default babelOptions are:

{
  babelrc: false,
  sourceMaps: true,
  plugins: [/* our custom plugin to do this extraction */],
  parserOpts: {plugins: [/* all of them except estree */]},
}

This is shallowly merged, with the exception of plugins. You can specify any plugins you want and we'll make sure we always include our own plugin to do the precompiling. (You're welcome).

Inspiration

I started thinking about this around here.

Other Solutions

I'm not aware of any, if you are please make a pull request and add it here!

Contributors

Thanks goes to these people (emoji key):


Kent C. Dodds

πŸ’» πŸ“– πŸš‡ ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].