Coder Social home page Coder Social logo

sassify's Introduction

sassify

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

Build Status Dependency Status devDependency Status

Currently breaks in some cases on node 0.11.x with latest version (2.0.1) of node-sass as documented in node-sass issue #550. This is also the reason why node 0.11 is currently not supported. Use at your own risk (though no actual risk is involved, it might just not work).

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');

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

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

require('./style.sass');

Install sassify into your app:

$ npm install sassify

When you compile your app, just pass -t sassify to browserify:

$ browserify -t sassify entry.js > bundle.js

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, {
        'auto-inject': true, // Inject css directly in the code
        base64Encode: false, // Use base64 to inject css
        sourceMap: false // Add source map to the code
      });

  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.

Install

sassify

License

MIT

sassify's People

Contributors

davidguttman avatar call-a3 avatar codeflyer avatar jeffling avatar aslansky avatar ggarek avatar pdufour avatar thom4parisot avatar

Watchers

James Cloos avatar 3λiȯ+ avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.