@node-sitecore/scssify

1.0.1 • Public • Published

@node-sitecore/scssify

Simple middleware and method for Browserify to add Sass styles to the browser.

Example

If you have a file entry.js that you want to require some css from style.scss:

style.scss:

body {
  background: pink;
}

entry.js:

require('./style.scss');

import "./style.css";

console.log('The background is pink!')

Or indented Sass syntax may be used with the .sass extension:

require('./style.sass');

Install @node-sitecore/scssify into your app:

$ npm install @node-sitecore/scssify

Gulp task example

...or you can do it using a gulp task.

var gulp = require('gulp');
var browserify = require('browserify');
var sassify = require('sassify');
var source = require('vinyl-source-stream');

gulp.task('build', function(done) {
  var result = browserify({})
      .transform(sassify, {
        output: "./bundle.css",
        sourceMap: false, 
        pipes: [
          postcss([
            autoprefixer({ browsers: config.autoPrefixerBrowsers }),
            cssnano({
              zindex: false
            })
          ])
        ]
      });

  result.add('./entry.js');
  result.bundle()
      .pipe(source('output.js'))
      .pipe(gulp.dest('./'))
      .on('end', function(err) {
        if (err) {
          done(err);
        } else {
          done();
        }
      });
});

Imports

Sass allows one to @import other Sass files. This module synchronously imports those dependencies at the time of the bundling. It looks for the imported files in both the directory of the parent file and the folder where the module itself lives, so it should work so long as the paths in the @import commands are correct relative to the importing file, as usual. It is not currently tested for recursive importing.

License

The MIT License (MIT)

Copyright (c) 2018 NodeSitecore

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Dependents (0)

Package Sidebar

Install

npm i @node-sitecore/scssify

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

31.5 kB

Total Files

14

Last publish

Collaborators

  • romakita
  • timbenniks