v0.6.2
This release contains some bugfixes, as well as a new way to consume Ember CLI Tailwind from your addons. Here's the relevant section from the README at the time of this release.
Advanced addon usage
build-tailwind
and the shouldBuildTailwind
option
Ember CLI Tailwind comes with a function you can use when you want more control over how to work with the built tailwind.css
file.
The function is in the lib
directory and can be require
'd in node:
const buildTailwind = require('ember-cli-tailwind/lib/build-tailwind');
To use the function, pass in your addon instance (usually this
if you're working in a hook in index.js
):
let tailwind = buildTailwind(this);
The return value is a Broccoli tree, and thus can be used in different treeFor
hooks to end up in your build.
If you're using this, you probably also want to disable Ember CLI Tailwind's default behavior, which will concat the built tailwind.css
file into your addon's generated vendor.css
file – otherwise you could end up with two versions of Tailwind in your CSS.
You can do that using the shouldBuildTailwind
config option:
// index.js
module.exports = {
name: 'your-addon',
options: {
'ember-cli-tailwind': {
shouldBuildTailwind: false
}
}
}
Now you are responsible for calling buildTailwind
and ensuring the resulting tree ends up in your output.
As an example of how you might use this, say you're building a UI component library as an Ember Addon. You want your component library to use Ember CLI Tailwind, but you're using Sass, and you'd like to explicitly @import
the built tailwind.css
file in your component library so that you can write other CSS classes that @extend
Tailwind's classes.
Here's what that would look like:
// index.js
const buildTailwind = require('ember-cli-tailwind/lib/build-tailwind');
module.exports = {
name: 'your-addon',
config() {
return {
'ember-cli-tailwind': {
shouldBuildTailwind: false
}
};
},
treeForAddonStyles(tree) {
let trees = tree ? [ tree ] : [];
trees.push(buildTailwind(this));
return new MergeTrees(trees);
}
};
Now that the built tailwind.css
file is in your Addon's style tree, you can import it in other Sass files:
// addon/styles/addon.scss
@import 'tailwind';
body {
@extend .antialiased;
@extend .font-sans;
@extend .text-grey-darkest;
}
You could even use Sass variables inside of Tailwind's config, since you can set those variables before @import
'ing Tailwind:
// tailwind/config/colors.js
export default {
brand: '$brand'
}
$brand: '#3490DC';
@import 'tailwind';