Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart sass #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"parserOptions": {
"ecmaVersion": 9,
"ecmaFeatures": {
"impliedStrict": true
}
},
"env": {
"node": true
},
"extends": [
"eslint:recommended"
],
"rules": {
"no-console": 0
}
}
26 changes: 26 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Verify
on:
push:
branches: [ master, dart-sass ]
pull_request:
branches: [ master, dart-sass ]

jobs:
verify:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- name: Run Lint and Test
run: npm run lint && npm test
15 changes: 0 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Fetch!
Copyright (c) 2021, Fetch!

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
66 changes: 52 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# 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)
# Node SASS Asset functions

To ease the transitioning from Compass to Libsass, this module provides some of Compass' asset functions for [node-sass](https://github.com/sass/node-sass)
> Exposes a set of functions to Sass that keep physical asset location details out of your source code. Also allows one to define a cache-busting policy or specify specific asset hosts.

_**NB** Please note that the `functions` option of node-sass is still experimental (>= v3.0.0)._
![Verify](https://github.com/fetch/node-sass-asset-functions/workflows/Verify/badge.svg)
[![npmjs](https://badge.fury.io/js/node-sass-asset-functions.svg)](https://www.npmjs.com/package/node-sass-asset-functions)

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

## Origin

Originally created for transition from Compass to Libsass, this module provides some of the asset functions that came with [Compass](http://compass-style.org). Tested with [dart-sass](https://github.com/sass/dart-sass) or [node-sass](https://github.com/sass/node-sass).

## Breaking Change 1.0.0

* [node-sass](https://github.com/sass/node-sass) is [deprecated](https://sass-lang.com/blog/libsass-is-deprecated)
* Default Sass compiler is now the [dart-sass](https://github.com/sass/dart-sass) javascript implementation.
* New option `sass` allows you to override the default compiler.
* Dart Sass is now the [primary implementation of Sass](https://sass-lang.com/dart-sass), and the default sass compiler.

## Installation

Expand All @@ -15,12 +29,14 @@ npm install --save[-dev] node-sass-asset-functions
Basic usage is as easy as setting the `functions` property:

```js
var sass = require('node-sass');
var assetFunctions = require('node-sass-asset-functions');
const sass = require('sass');
const fiber = require('fibers');
const assetFunctions = require('node-sass-asset-functions');

sass.render({
functions: assetFunctions(),
file: scss_filename,
fiber, // dart-sass async render performance detail
[, options..]
}, function(err, result) { /*...*/ });
```
Expand All @@ -39,15 +55,32 @@ You can specify the paths of your resources using the following options (shown w
So if for example your images reside in `public/img` instead of `images/images`, you use it as follows:

```js
var sass = require('node-sass');
var assetFunctions = require('node-sass-asset-functions');
const sass = require('sass');
const fiber = require('fibers');
const assetFunctions = require('node-sass-asset-functions');

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

### Overriding the default compiler with Node-Sass

Example using the node-sass compiler using the new option `sass`.

```js
const sass = require('node-sass');
const assetFunctions = require('node-sass-asset-functions');

sass.render({
functions: assetFunctions({ sass }),
file: scss_filename,
[, options..]
}, function(err, result) { /*...*/ });
```
Expand All @@ -66,6 +99,7 @@ sass.render({
}
}),
file: scss_filename,
fiber,
[, options..]
}, function(err, result) { /*...*/ });
```
Expand All @@ -82,6 +116,7 @@ sass.render({
}
}),
file: scss_filename,
fiber,
[, options..]
}, function(err, result) { /*...*/ });
```
Expand All @@ -93,28 +128,31 @@ Here we include the file's hexdigest in the path, using the [`hexdigest`](https
For example, `/images/myimage.png` would become `/images/myimage-8557f1c9b01dd6fd138ba203e6a953df6a222af3.png`.

```js
var path = require('path')
, fs = require('fs')
, hexdigest = require('hexdigest');
const sass = require('sass');
const fiber = require('fibers');
const path = require('path');
const fs = require('fs');
const 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.
// an error occurred, maybe the file doesn't exist.
// 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;
const extname = path.extname(http_path);
const basename = path.basename(http_path, extname);
const new_name = `${basename}-${digest}${extname}`;
done({path: path.join(path.dirname(http_path), new_name), query: null});
}
});
}
}),
file: scss_filename,
fiber,
[, options..]
}, function(err, result) { /*...*/ });
```
Expand Down
Loading