2.0.0-beta.1 • Published 6 years ago

tailwindcss-export-config v2.0.0-beta.1

Weekly downloads
755
License
MIT
Repository
github
Last release
6 years ago

Features

  • :rocket: Exports Tailwindcss config options to SASS, SCSS, LESS and Stylus.
  • :boom: CLI and Node api support
  • :muscle: Unit Tested

Getting started

  1. Using npm: npm install tailwindcss-export-config

or with yarn:

yarn add tailwindcss-export-config

  1. Make a package.json script and run it for convenience
{
  "scripts": {
    "export-tailwind-config": "tailwindcss-export-config --config=src/styles/tailwind/tailwind.config.js --destination=src/styles/scss/tailwind-configs --format=scss"
  }
}

or import inside your own node script

import TailwindExportConfig from 'tailwindcss-export-config'
const converter = new TailwindExportConfig({
  config: 'path/to/tailwind.config.js',
  destination: 'converted/file/destination',
  format: 'scss',
  prefix: 'tw',
  flat: true
})
// writeToFile returns a promise so we can chain off it
converter.writeToFile().then(() => {
  console.log('Success')
}).catch((error) => {
  console.log('Oops', error.message)
})

Config Options

All options are available to the CLI and node package. Type tailwindcss-export-config --h for help.

PropTypeRequiredDescription
configString,ObjecttrueTailwindcss config path or config object to transform
destinationStringtrueDestination to save converted file
formatStringtrueThe format in which to convert the file
prefixStringfalseAn optional prefix for each variable name
flatBooleanfalseOptionally transforms the variables from nested maps to flat level variables. Less does not support nested maps so we default to flat for them always.

Example export

Lets get a portion of the Tailwind config

module.exports = {
  colors: {
    'transparent': 'transparent',
    'black': '#22292f',
    'grey-darkest': '#3d4852',
    'grey-darker': '#606f7b',
    'grey-dark': '#8795a1',
    'grey': '#b8c2cc',
    'grey-light': '#dae1e7',
    'grey-lighter': '#f1f5f8',
    'grey-lightest': '#f8fafc',
    'white': '#ffffff',
  }
}

How would this look in the various preprocessors? Whats does the flat param do?

SCSS

Using the flat param we get:

$colors-transparent: transparent;
$colors-black: #22292f;
$colors-grey-darkest: #3d4852;
$colors-grey-darker: #606f7b;
$colors-grey-dark: #8795a1;
$colors-grey: #b8c2cc;
$colors-grey-light: #dae1e7;
$colors-grey-lighter: #f1f5f8;
$colors-grey-lightest: #f8fafc;
$colors-white: #ffffff;

or without with the flat param set to false

$colors: (
  transparent: transparent,
  black: #22292f,
  grey-darkest: #3d4852,
  grey-darker: #606f7b,
  grey-dark: #8795a1,
  grey: #b8c2cc,
  grey-light: #dae1e7,
  grey-lighter: #f1f5f8,
  grey-lightest: #f8fafc,
  white: #ffffff
);

The second (nested map) approach is a bit more annoying to work with as you have to do map_get($colors, black) but things are easier to loop if you need to.

Sass is almost the same and you can import both sass and scss vars into the same project. We support them both if someone prefers one syntax over the other.

LESS

@colors-transparent: transparent;
@colors-black: #22292f;
@colors-grey-darkest: #3d4852;
@colors-grey-darker: #606f7b;
@colors-grey-dark: #8795a1;
@colors-grey: #b8c2cc;
@colors-grey-light: #dae1e7;
@colors-grey-lighter: #f1f5f8;
@colors-grey-lightest: #f8fafc;
@colors-white: #ffffff;

Less does not have nested maps so passing the flat param will not do anything

Stylus

$colors-transparent = transparent
$colors-black = #22292f
$colors-grey-darkest = #3d4852
$colors-grey-darker = #606f7b
$colors-grey-dark = #8795a1
$colors-grey = #b8c2cc
$colors-grey-light = #dae1e7
$colors-grey-lighter = #f1f5f8
$colors-grey-lightest = #f8fafc
$colors-white = #ffffff

or with the flat param to false

$colors = {
  transparent: transparent,
  black: #22292f,
  grey-darkest: #3d4852,
  grey-darker: #606f7b,
  grey-dark: #8795a1,
  grey: #b8c2cc,
  grey-light: #dae1e7,
  grey-lighter: #f1f5f8,
  grey-lightest: #f8fafc,
  white: #ffffff
}

Using the colors is a matter of reaching using dot notation $colors.black or $colors[black].

Prefix

You can prefix the colors to escape naming collisions by using the prefix param

--prefix=tw

$tw-colors-transparent: transparent;
$tw-colors-black: #22292f;
$tw-colors-grey-darkest: #3d4852;
$tw-colors-grey-darker: #606f7b;
$tw-colors-grey-dark: #8795a1;
$tw-colors-grey: #b8c2cc;
$tw-colors-grey-light: #dae1e7;
$tw-colors-grey-lighter: #f1f5f8;
$tw-colors-grey-lightest: #f8fafc;
$tw-colors-white: #ffffff;
4.1.0

3 years ago

4.0.1

3 years ago

3.1.0

4 years ago

4.0.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.3.1

4 years ago

2.3.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.5

6 years ago

2.0.0-beta.1

6 years ago

2.0.0-beta.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago