import BalmTask from './balm' ; import { MP_ASSETS } from '../../config/constants' ; import { BalmError } from '@balm-core/index' ; class BalmStyleTask extends BalmTask { constructor ( name ) { super ( name ) ; let extname ; switch ( name ) { case 'sass' : extname = '{scss,sass}' ; break ; case 'less' : extname = 'less' ; break ; default : extname = 'css' ; } this . defaultInput = path . join ( BalmJS . config . src . css , '**' , `!(_*).${ extname }` ) ; this . defaultOutput = BalmJS . config . env . isMP ? path . join ( BalmJS . config . dest . base , MP_ASSETS , BalmJS . config . paths . target . css ) : BalmJS . config . dest . css ; } handleStyle ( style , output , options ? ) { const taskName = `${ this . name } task` ; const shouldUseSourceMap = ! ( BalmJS . config . env . isProd || BalmJS . config . styles . minify ) ; let stream = gulp . src ( this . input , Object . assign ( { sourcemaps : shouldUseSourceMap , allowEmpty : true } , this . gulpSrcOptions ) ) . pipe ( BalmJS . plugins . plumber ( function ( this , error ) : void { BalmJS . logger . error ( taskName , error . message ) ; this . emit ( 'end' ) ; this . destroy ( ) ; } ) ) ; switch ( style ) { case 'sass' : stream = stream . pipe ( BalmJS . plugins . sass ( options ) ) ; break ; case 'less' : stream = stream . pipe ( BalmJS . plugins . less ( options ) ) ; break ; default : } return stream . pipe ( BalmJS . plugins . postcss ( BalmJS . plugins . postcssPlugins ( style === 'postcss' ) ) ) . pipe ( $ . if ( BalmJS . config . env . isMP , BalmJS . plugins . rename ( { extname : '.wxss' } ) ) ) . pipe ( gulp . dest ( output , { sourcemaps : shouldUseSourceMap } ) ) . pipe ( server . reload ( { stream : true } ) ) ; } } export default BalmStyleTask ;