Skip to content

Instantly share code, notes, and snippets.

@tjbenton
Created August 5, 2016 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjbenton/3ab986c154e0ca04b659096bb50cb645 to your computer and use it in GitHub Desktop.
Save tjbenton/3ab986c154e0ca04b659096bb50cb645 to your computer and use it in GitHub Desktop.
Fly task to compile styles
export async function styles() {
await this.start([ 'stylesSite', 'stylesPages' ], { parallel: true })
}
export async function stylesWatch() {
await Promise.all([
this.watch('app/styles/**/{site,_*}.scss', 'stylesSite'),
this.watch([ 'app/styles/tools/**/_*.scss', 'app/styles/pages/**/*.scss' ], 'stylesPages'),
])
}
export async function stylesSite() {
await this.clear('dist/styles/site*')
await this.source('app/styles/site.scss')
.sass(options)
.target('dist/styles');
await postcss.call(this, 'dist/styles/site.css', 'dist/styles');
}
export async function stylesPages() {
await this.clear('dist/styles/pages/**/*'));
await this
.source('app/styles/pages/**/*.scss')
.sass(options)
.target'dist/styles/pages'));
await postcss.call(this, 'dist/styles/pages/**/*.css', 'dist/styles/pages');
}
// this is a helper function that processes the css after it's been compiled
// and run the css files through `autoprefixer` and combine the `media queries`
async function postcss(source, target) {
await this
.source(source)
.postcss({
plugins: [
require('autoprefixer')({
browsers: [ 'last 2 versions', '> 5%', 'Android >= 4', 'Chrome >= 40', 'ie >= 10', 'edge >= 12', 'iOS >= 7', ],
cascade: false
}),
require('css-mqpacker')
]
})
.target(target);
const cssnano = require('cssnano')({ discardComments: { removeAll: true }, zindex: false });
await this
.source(source)
.filter(extention) // duplicate the file and add the .min extention
.postcss({ plugins: process.env.PRODUCTION ? [ cssnano ] : [] })
.target(target);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment