{"id":15041611,"url":"https://github.com/fetch/node-sass-asset-functions","last_synced_at":"2025-04-14T20:22:47.888Z","repository":{"id":35058090,"uuid":"39193121","full_name":"fetch/node-sass-asset-functions","owner":"fetch","description":"Node SASS Asset functions","archived":false,"fork":false,"pushed_at":"2022-02-17T21:04:18.000Z","size":474,"stargazers_count":45,"open_issues_count":8,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T08:41:25.205Z","etag":null,"topics":["compass","grunt","node-sass","sass"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/node-sass-asset-functions","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fetch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-16T11:26:16.000Z","updated_at":"2021-09-27T02:15:55.000Z","dependencies_parsed_at":"2022-09-16T05:21:31.492Z","dependency_job_id":null,"html_url":"https://github.com/fetch/node-sass-asset-functions","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetch%2Fnode-sass-asset-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetch%2Fnode-sass-asset-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetch%2Fnode-sass-asset-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fetch%2Fnode-sass-asset-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fetch","download_url":"https://codeload.github.com/fetch/node-sass-asset-functions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952841,"owners_count":21188512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compass","grunt","node-sass","sass"],"created_at":"2024-09-24T20:46:17.084Z","updated_at":"2025-04-14T20:22:47.867Z","avatar_url":"https://github.com/fetch.png","language":"JavaScript","readme":"# Node SASS Asset functions [![Build Status](https://travis-ci.org/fetch/node-sass-asset-functions.svg?branch=master)](https://travis-ci.org/fetch/node-sass-asset-functions) [![npmjs](https://badge.fury.io/js/node-sass-asset-functions.svg)](https://www.npmjs.com/package/node-sass-asset-functions)\n\nTo ease the transitioning from Compass to Libsass, this module provides some of Compass' asset functions for [node-sass](https://github.com/sass/node-sass)\n\n_**NB** Please note that the `functions` option of node-sass is still experimental (\u003e= v3.0.0)._\n\n## Installation\n\n```\nnpm install --save[-dev] node-sass-asset-functions\n```\n\n## Usage\n\nBasic usage is as easy as setting the `functions` property:\n\n```js\nvar sass = require('node-sass');\nvar assetFunctions = require('node-sass-asset-functions');\n\nsass.render({\n  functions: assetFunctions(),\n  file: scss_filename,\n  [, options..]\n}, function(err, result) { /*...*/ });\n```\n\nYou can specify the paths of your resources using the following options (shown with defaults):\n\n```js\n{\n  images_path: 'public/images',\n  fonts_path: 'public/fonts',\n  http_images_path: '/images',\n  http_fonts_path: '/fonts'\n}\n```\n\nSo if for example your images reside in `public/img` instead of `images/images`, you use it as follows:\n\n```js\nvar sass = require('node-sass');\nvar assetFunctions = require('node-sass-asset-functions');\n\nsass.render({\n  functions: assetFunctions({\n    images_path: 'public/img',\n    http_images_path: '/img'\n  }),\n  file: scss_filename,\n  [, options..]\n}, function(err, result) { /*...*/ });\n```\n\n### Additional options\n\n#### `asset_host`: a function which completes with a string used as asset host.\n\n```js\nsass.render({\n  functions: assetFunctions({\n    asset_host: function(http_path, done){\n      done('http://assets.example.com');\n      // or use the supplied path to calculate a host\n      done('http://assets' + (http_path.length % 4) + '.example.com');\n    }\n  }),\n  file: scss_filename,\n  [, options..]\n}, function(err, result) { /*...*/ });\n```\n\n#### `asset_cache_buster`: a function to rewrite the asset path\n\nWhen this function returns a string, it's set as the query of the path. When returned an object, `path` and `query` will be used.\n\n```js\nsass.render({\n  functions: assetFunctions({\n    asset_cache_buster: function(http_path, real_path, done){\n      done('v=123');\n    }\n  }),\n  file: scss_filename,\n  [, options..]\n}, function(err, result) { /*...*/ });\n```\n\n##### A more advanced example:\n\nHere we include the file's  hexdigest in the path, using the [`hexdigest`](https://github.com/koenpunt/node-hexdigest) module.\n\nFor example, `/images/myimage.png` would become `/images/myimage-8557f1c9b01dd6fd138ba203e6a953df6a222af3.png`.\n\n```js\nvar path = require('path')\n  , fs = require('fs')\n  , hexdigest = require('hexdigest');\n\nsass.render({\n  functions: assetFunctions({\n    asset_cache_buster: function(http_path, real_path, done){\n      hexdigest(real_path, 'sha1', function(err, digest) {\n        if (err) {\n          // an error occurred, maybe the file doesn't exists.\n          // Calling `done` without arguments will result in an unmodified path.\n          done();\n        } else {\n          var extname = path.extname(http_path)\n            , basename = path.basename(http_path, extname);\n          var new_name = basename + '-' + digest + extname;\n          done({path: path.join(path.dirname(http_path), new_name), query: null});\n        }\n      });\n    }\n  }),\n  file: scss_filename,\n  [, options..]\n}, function(err, result) { /*...*/ });\n```\n\n### Available functions\n\n- `image-url($filename: null, $only_path: false)`\n- `image-width($filename: null)`\n- `image-height($filename: null)`\n- `font-url($filename: null, $only-path: false)`\n- `font-files($filenames...)`\n- and more to come\n\n### Usage with Grunt\n\nUsing this module with Grunt is just as easy:\n\n```js\nvar assetFunctions = require('node-sass-asset-functions');\n\nmodule.exports = function(grunt){\n  grunt.initConfig({\n    // ...\n    sass: {\n      options: {\n        functions: assetFunctions()\n      },\n      dist: {\n        'public/stylesheets/application.css': 'app/assets/stylesheets/application.css.scss'\n      }\n    }\n    // ...\n  });\n};\n```\n\n## See also\n\n[`node-sass-css-importer`](https://github.com/fetch/node-sass-css-importer): Import CSS files into `node-sass`, just like [`sass-css-importer`](https://github.com/chriseppstein/sass-css-importer) did for Compass  \n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffetch%2Fnode-sass-asset-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffetch%2Fnode-sass-asset-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffetch%2Fnode-sass-asset-functions/lists"}