All Projects → fetch → node-sass-asset-functions

fetch / node-sass-asset-functions

Licence: MIT license
Node SASS Asset functions

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to node-sass-asset-functions

Grunt Html
Grunt plugin for html validation
Stars: ✭ 165 (+266.67%)
Mutual labels:  grunt
Grunt Webpack
integrate webpack into grunt build process
Stars: ✭ 249 (+453.33%)
Mutual labels:  grunt
Student-course-selection-system
Vue+express:高校学生选课系统 亮点:前后端分离
Stars: ✭ 25 (-44.44%)
Mutual labels:  node-sass
Hexo Theme Laughing
A lightweight hexo theme
Stars: ✭ 185 (+311.11%)
Mutual labels:  grunt
Grunt Recess
[DEPRECATED] Lint and minify CSS and LESS
Stars: ✭ 205 (+355.56%)
Mutual labels:  grunt
TypeScript-AMD-Boilerplate
A TypeScript AMD Grunt Boilerplate with RequireJS
Stars: ✭ 46 (+2.22%)
Mutual labels:  grunt
Grunt Sftp Deploy
Grunt task for code deployment over sftp
Stars: ✭ 158 (+251.11%)
Mutual labels:  grunt
grunt-angular-combine
Grunt task for combining AngularJS partials into a single HTML file.
Stars: ✭ 16 (-64.44%)
Mutual labels:  grunt
Jqplot
A Versatile and Expandable jQuery Plotting Plugin
Stars: ✭ 219 (+386.67%)
Mutual labels:  grunt
diwako dui
A UI showing unit positions and names of units in your squad
Stars: ✭ 39 (-13.33%)
Mutual labels:  compass
My Wallet V3 Frontend
Blockchain Web Wallet Frontend
Stars: ✭ 192 (+326.67%)
Mutual labels:  grunt
Grunt Image
Optimize PNG, JPEG, GIF, SVG images with grunt task.
Stars: ✭ 201 (+346.67%)
Mutual labels:  grunt
OBComapssView
A sample project for finding the Qiblah direction in iOS swift
Stars: ✭ 14 (-68.89%)
Mutual labels:  compass
Grunt Saucelabs
Grunt task for running all your browser tests using Sauce Labs
Stars: ✭ 182 (+304.44%)
Mutual labels:  grunt
html-sass-jumpstart
Minimal Sass/HTML Template Site - dart sass powered, includes stylelint and prettier, and autoprefix upon build. develop script includes hot-reload via browsersync.
Stars: ✭ 82 (+82.22%)
Mutual labels:  node-sass
Grunt Wp I18n
Internationalize WordPress themes and plugins with Grunt.
Stars: ✭ 163 (+262.22%)
Mutual labels:  grunt
feweekly
⭐ 前端周刊,让你在前端领域跟上时代的脚步,深度和广度不断精进
Stars: ✭ 34 (-24.44%)
Mutual labels:  grunt
grunt-wp-css
Format style sheets according to the WordPress CSS coding standards.
Stars: ✭ 36 (-20%)
Mutual labels:  grunt
grunt-frontend-boilerplate
🔒 Basic boilerplate to start a webapp project with Angular.js, Bootstrap and Grunt
Stars: ✭ 14 (-68.89%)
Mutual labels:  grunt
danmallme
DanMall.me
Stars: ✭ 97 (+115.56%)
Mutual labels:  grunt

Node SASS Asset functions Build Status npmjs

To ease the transitioning from Compass to Libsass, this module provides some of Compass' asset functions for node-sass

NB Please note that the functions option of node-sass is still experimental (>= v3.0.0).

Installation

npm install --save[-dev] node-sass-asset-functions

Usage

Basic usage is as easy as setting the functions property:

var sass = require('node-sass');
var assetFunctions = require('node-sass-asset-functions');

sass.render({
  functions: assetFunctions(),
  file: scss_filename,
  [, options..]
}, function(err, result) { /*...*/ });

You can specify the paths of your resources using the following options (shown with defaults):

{
  images_path: 'public/images',
  fonts_path: 'public/fonts',
  http_images_path: '/images',
  http_fonts_path: '/fonts'
}

So if for example your images reside in public/img instead of images/images, you use it as follows:

var sass = require('node-sass');
var assetFunctions = require('node-sass-asset-functions');

sass.render({
  functions: assetFunctions({
    images_path: 'public/img',
    http_images_path: '/img'
  }),
  file: scss_filename,
  [, options..]
}, function(err, result) { /*...*/ });

Additional options

asset_host: a function which completes with a string used as asset host.

sass.render({
  functions: assetFunctions({
    asset_host: function(http_path, done){
      done('http://assets.example.com');
      // or use the supplied path to calculate a host
      done('http://assets' + (http_path.length % 4) + '.example.com');
    }
  }),
  file: scss_filename,
  [, options..]
}, function(err, result) { /*...*/ });

asset_cache_buster: a function to rewrite the asset path

When this function returns a string, it's set as the query of the path. When returned an object, path and query will be used.

sass.render({
  functions: assetFunctions({
    asset_cache_buster: function(http_path, real_path, done){
      done('v=123');
    }
  }),
  file: scss_filename,
  [, options..]
}, function(err, result) { /*...*/ });
A more advanced example:

Here we include the file's hexdigest in the path, using the hexdigest module.

For example, /images/myimage.png would become /images/myimage-8557f1c9b01dd6fd138ba203e6a953df6a222af3.png.

var path = require('path')
  , fs = require('fs')
  , hexdigest = require('hexdigest');

sass.render({
  functions: assetFunctions({
    asset_cache_buster: function(http_path, real_path, done){
      hexdigest(real_path, 'sha1', function(err, digest) {
        if (err) {
          // an error occurred, maybe the file doesn't exists.
          // Calling `done` without arguments will result in an unmodified path.
          done();
        } else {
          var extname = path.extname(http_path)
            , basename = path.basename(http_path, extname);
          var new_name = basename + '-' + digest + extname;
          done({path: path.join(path.dirname(http_path), new_name), query: null});
        }
      });
    }
  }),
  file: scss_filename,
  [, options..]
}, function(err, result) { /*...*/ });

Available functions

  • image-url($filename: null, $only_path: false)
  • image-width($filename: null)
  • image-height($filename: null)
  • font-url($filename: null, $only-path: false)
  • font-files($filenames...)
  • and more to come

Usage with Grunt

Using this module with Grunt is just as easy:

var assetFunctions = require('node-sass-asset-functions');

module.exports = function(grunt){
  grunt.initConfig({
    // ...
    sass: {
      options: {
        functions: assetFunctions()
      },
      dist: {
        'public/stylesheets/application.css': 'app/assets/stylesheets/application.css.scss'
      }
    }
    // ...
  });
};

See also

node-sass-css-importer: Import CSS files into node-sass, just like sass-css-importer did for Compass

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].