ludohenin / gulp-inline-ng2-template

Gulp plugin to inline HTML and CSS into Angular 2 component decorators
MIT License
126 stars 26 forks source link

How to use scss file with your gulp task #83

Open ofirrifo opened 7 years ago

ofirrifo commented 7 years ago

Hi,

Thanks for great gulp package.

How can I use this gulp package with scss files

Thanks

aelbore commented 7 years ago

78 Can you take a look on this? if this solve your issue.

aelbore commented 7 years ago
const sass = require('node-sass');
const inlineNg2Template = require('gulp-inline-ng2-template');

const styleProcessor = (stylePath, ext, styleFile, callback) => {
  if (ext[0] === '.scss') {
    let sassObj = sass.renderSync({ file: stylePath });
    if (sassObj && sassObj['css']){
      styleFile = sassObj.css.toString('utf8');
    }
  }
  return callback(null, styleFile);  
};

const OPTIONS = {
  base: 'src', 
  useRelativePaths: true,
  styleProcessor: styleProcessor
}; 

const ng2InlineTemplate = () => {
  return inlineNg2Template(OPTIONS);
};

exports.ng2InlineTemplate = ng2InlineTemplate;