10 examples of 'npm node sass' in JavaScript

Every line of 'npm node sass' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
10function style(node, cb) {
11 if(node.type === MIME) {
12
13 opts.file = node.file;
14 opts.data = node.contents;
15
16 processor.render(
17 opts,
18 (err, res) => {
19 if(err) {
20 return cb(err);
21 }
22 node.contents = res.css.toString();
23 cb()
24 }
25 );
26
27 }else{
28 cb();
29 }
30}
Important

Use secure code every time

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

69function sass() {
70 return gulp.src('src/assets/scss/app.scss')
71 .pipe($.sourcemaps.init())
72 .pipe($.sass({
73 includePaths: PATHS.sass
74 })
75 .on('error', $.sass.logError))
76 .pipe($.autoprefixer({
77 browsers: COMPATIBILITY
78 }))
79 .pipe($.if(PRODUCTION, $.uncss(UNCSS_OPTIONS)))
80 .pipe($.if(PRODUCTION, $.cssnano()))
81 .pipe($.if(!PRODUCTION, $.sourcemaps.write()))
82 .pipe(gulp.dest(PATHS.dist + '/assets/css'))
83 .pipe(browser.reload({ stream: true }));
84}
40function sass() {
41 return gulp
42 .src("./src/styles/**/*.scss")
43 .pipe(
44 gulpSass.sync({ outputStyle: "expanded" }).on("error", gulpSass.logError)
45 )
46 .pipe(autoprefixer())
47 .pipe(gulp.dest("./dist/css"));
48}
7var sassTask = function sassTask(options) {
8 var gulp = options.gulp;
9 var config = options.config;
10 var dirs = config.directories;
11 var plugins = options.plugins;
12 var rootPath = options.rootPath;
13 var browserSync = options.browserSync;
14 var source = path.join(rootPath, dirs.source, dirs.styles, '/*.{scss,sass}');
15
16 // Serve
17 gulp.task('sass:serve', function () {
18 var dest = path.join(rootPath, dirs.temporary, dirs.styles.replace(/^_/, ''));
19 gulp.src(source)
20 .pipe(plugins.plumber())
21 .pipe(plugins.sourcemaps.init())
22 .pipe(plugins.sass({
23 outputStyle: 'expanded',
24 precision: 10,
25 includePaths: [path.join(rootPath, dirs.source, dirs.styles) ]
26 }).on('error', plugins.sass.logError))
27 .pipe(plugins.postcss([autoprefixer({browsers: ['ie >= 9']})]))
28 .pipe(plugins.sourcemaps.write())
29 .pipe(gulp.dest(dest))
30 .pipe(browserSync.stream());
31 });
32
33 // Build
34 gulp.task('sass:build', function () {
35 var dest = path.join(rootPath, dirs.destination, dirs.styles.replace(/^_/, ''));
36 gulp.src(source)
37 .pipe(plugins.plumber())
38 .pipe(plugins.sourcemaps.init())
39 .pipe(plugins.sass({
40 outputStyle: 'compressed',
41 precision: 10,
42 includePaths: [path.join(rootPath, dirs.source, dirs.styles) ]
43 }).on('error', plugins.sass.logError))
44 .pipe(plugins.postcss([autoprefixer({browsers: ['ie >= 9']})]))
45 .pipe(plugins.sourcemaps.write('.'))
46 .pipe(gulp.dest(dest));
47 });
48
49};
16constructor(inputNodes, options) {
17 super(inputNodes, {});
18
19 options = options || {};
20 Plugin.call(this, inputNodes, {
21 cacheInclude: options.cacheInclude || [/\.scss$/, /\.sass$/],
22 cacheExclude: options.cacheExclude || undefined
23 });
24 this.options = options;
25}
56function compileSass(sassFile, cssFile, isDebug) {
57 let result = sass.renderSync({
58 sourceMap: false,
59 file: sassFile,
60 outputStyle: isDebug ? "expanded" : "compressed"
61 });
62 if (result && result.css) {
63 result = result.css.toString();
64 if (cssFile) {
65 console.log("Compiling", cssFile);
66 fs.writeFileSync(cssFile, result, "utf8");
67 }
68 } else {
69 console.warn("No result from sass for ", sassFile);
70 }
71 return result;
72}
69function processSassMin() {
70 return gulp
71 .src('Styles/web.scss')
72 .pipe(sass())
73 .on('error', sass.logError)
74 .pipe(minifyCSS())
75 .pipe(concat('web.min.css'))
76 .pipe(gulp.dest(cssFolder));
77}
50function processSassMin() {
51 return gulp
52 .src('Styles/web.scss')
53 .pipe(sass())
54 .on('error', sass.logError)
55 .pipe(minifyCSS())
56 .pipe(concat('web.min.css'))
57 .pipe(gulp.dest(cssFolder));
58}
40function sassprod() {
41 return gulp.src(scssFiles)
42 .pipe(sass(sassProdOptions)
43 .on('error', sass.logError))
44 .pipe(rename('style.min.css'))
45 .pipe(gulp.dest(cssDest));
46}
24function sassBuildTask(dest, root, minify = false) {
25 return () => {
26 return gulp.src(_globify(root, '**/*.scss'))
27 .pipe(gulpSourcemaps.init({ loadMaps: true }))
28 .pipe(gulpSass().on('error', gulpSass.logError))
29 .pipe(gulpIf(minify, gulpCleanCss()))
30 .pipe(gulpSourcemaps.write('.'))
31 .pipe(gulp.dest(dest));
32 };
33}

Related snippets