How to use the node-sass.render function in node-sass

To help you get started, we’ve selected a few node-sass examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ericgio / react-bootstrap-typeahead / scripts / buildCSS.js View on Github external
function buildCSS(options) {
  // Get the base filename.
  let filename = options.file
    .split('/')
    .pop()
    .replace('.scss', '');

  // Denote minified CSS.
  if (options.outputStyle === 'compressed') {
    filename = `${filename}.min`;
  }

  // Render CSS files.
  sass.render(options, (err, result) => {
    if (err) {
      console.log(err);
      process.exit(1);
    }

    fs.writeFileSync(path.join(OUT_DIR, `${filename}.css`), result.css);
  });
}
github JasonEtco / flintcms / server / utils / compile-sass.js View on Github external
return new Promise((resolve, reject) => {
    sass.render(opt, (err, res) => {
      /* istanbul ignore if */
      if (err) reject(err)
      resolve(res)
    })
  })
}
github johnnybenson / sassr / lib / sassr.js View on Github external
function transform(opts, done) {
    opts = _.extend({}, SASS_DEFAULTS, opts);

    function cssPostProcessorDone(error, css) {
        if (error) {
            done(error);
            return;
        }

        // JSON.stringify protects against unescaped quotes winding up
        // in the modules that get generated.
        done(error, sassrModuleWith(JSON.stringify(css)));
    }

    sass.render(opts, function(error, result) {
        var css = error ? '' : result.css.toString();
        if (error || !_.isFunction(opts.cssPostProcessor)) {
            cssPostProcessorDone(error, css);
        } else {
            opts.cssPostProcessor(css, cssPostProcessorDone);
        }
    });
}
github ionic-team / ionic-app-scripts / src / sass.ts View on Github external
return new Promise((resolve, reject) => {

    sassConfig.omitSourceMapUrl = false;

    if (sassConfig.sourceMap) {
      sassConfig.sourceMapContents = true;
    }

    nodeSassRender(sassConfig, (sassError: SassError, sassResult: Result) => {
      const diagnostics = runSassDiagnostics(context, sassError);

      if (diagnostics.length) {
        printDiagnostics(context, DiagnosticsType.Sass, diagnostics, true, true);
        // sass render error :(
        reject(new BuildError('Failed to render sass to css'));

      } else {
        // sass render success :)
        renderSassSuccess(context, sassResult, sassConfig).then(outFile => {
          resolve(outFile);

        }).catch(err => {
          reject(new BuildError(err));
        });
      }
github triplecanopy / b-ber / packages / b-ber-tasks / src / sass / index.js View on Github external
new Promise(resolve =>
    nodeSass.render(
      {
        // Importer allows use of '~' to denote node_modules directory in SCSS files
        importer: (url, file, done) =>
          url[0] === '~'
            ? done({ file: resolveImportedModule(url.replace('~', '')) })
            : done({ file: url }),

        // Add build vars at runtime with the SCSS buffer (which is transformed
        // to string in the backticks)
        data: `$build: "${state.build}";${scssString}`,

        includePaths: [
          state.src.stylesheets(),
          path.dirname(state.theme.entry),
          path.dirname(path.dirname(state.theme.entry)),
        ],
github steveblue / angular2-rollup / build.utils.js View on Github external
postcssConfig += ' ' + cssProp;
            }

            if (!fs.existsSync(path.normalize(outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))))) {
                mkdir('-p', path.normalize(outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))));
            }

            if (cssConfig.env === 'prod' && filePath.indexOf(config.src + '/style') === -1) {

                if (!fs.existsSync(path.normalize('ngfactory/' + outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))))) {
                    mkdir('-p', path.normalize('ngfactory/' + outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))));
                }

            }

            sass.render(cssConfig.sassConfig, function (error, result) {
                if (error) {
                    warn(error.message, 'LINE: ' + error.line);
                    console.log('');
                } else {

                    fs.writeFile(outFile, result.css, function (err) {
                        if (err) {
                            warn(err);
                            console.log('');
                        }
                        if (!err && cssConfig.allowPostCSS === true) {

                            let postcss = exec(path.normalize(path.join(config.projectRoot, 'node_modules/.bin/postcss')) +
                                ' ' + outFile +
                                (cssConfig.sourceMap === false ? ' --no-map true' : '') +
                                ' -c ' + path.normalize(path.join(config.projectRoot, 'postcss.' + cssConfig.env + '.js')) +
github triplecanopy / b-ber / src / bber-modifiers / sass.jsx View on Github external
return new Promise((resolve, reject) => {
    nsass.render(options, (err1, result) => {
      if (err1) { return reject(err1) }
      if (!result) { return reject('Sass: `result` cannot be null.') }
      return postcss(autoprefixer(autoprefixerOptions))
        .process(result.css)
        .then(prefixed =>
          fs.writeFile(path.join(outputdir, 'application.css'), prefixed, (err2) => {
            if (err2) { reject(err2) }
            resolve()
          })
        )
    })
  })
}
github hellofresh / lentil / lib / ingredients / SASSIngredient.js View on Github external
return new Promise((resolve, reject) => {
            const localOptions = options;
            localOptions.includePaths.unshift(path.dirname(localOptions.file));
            localOptions.includePaths = localOptions.includePaths.unique();
            localOptions.sourceMap = localOptions.file;

            Logger.debug('Running node-sass with the following options', localOptions);

            sass.render(localOptions, (err, result) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(result);
                }
            });
        });
    }
github brightcove / videojs-contextmenu-ui / scripts / server.js View on Github external
sass(resolve, reject) {
    sass.render({
      file: srces.css,
      outputStyle: 'compressed'
    }, (err, result) => {
      if (err) {
        reject(err.message);
      } else {
        fs.writeFile(dests.css, result.css, (errr) => {
          if (errr) {
            reject(errr.message);
          } else {
            resolve();
          }
        });
      }
    });
  },
github thealjey / webcompiler / lib / SASSCompile.js View on Github external
run(inPath: string, outPath: string, callback: any) {
    render(Object.assign({}, options, {
      file: inPath,
      outFile: outPath,
      importOnce: this.importOnce,
      includePaths: this.includePaths
    }), function (e, result) {
      if (e) {
        return callback(e);
      }
      callback(null, {code: result.css, map: result.map.toString()});
    });
  }