@localnerve/sass-asset-functions 7.1.1 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/README.md +37 -30
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
# Sass Asset Functions
|
|
2
2
|
|
|
3
|
-
> Supplies a set of functions to Sass that keep physical asset location details out of your source code.
|
|
3
|
+
> Supplies a set of functions to Sass that keep physical asset location details out of your source code. Allows one to define a cache-busting policy, specify asset hosts by url, and use arbitrary build-time metadata to drive css generation.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
[](https://badge.fury.io/js/%40localnerve%2Fsass-asset-functions)
|
|
7
7
|
[](https://coveralls.io/github/localnerve/sass-asset-functions?branch=master)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
For example, the `image-url` used here in place of `url` adds build-time configuration to resolve the file to the proper location as seen from the web:
|
|
9
|
+
## Overview
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
.some-selector {
|
|
14
|
-
background-image: image-url('cat.jpg');
|
|
15
|
-
}
|
|
16
|
-
```
|
|
11
|
+
This module provides a set of Sass functions that help with asset management in web projects, similar to what Compass provided. You can use functions like `image-url()` instead of plain `url()` and the module will automatically resolve paths correctly based on your build configuration. Further, you can expose arbitrary built-time metadata (typically from image processors) for use in sass to generate image references, dimensions, types, breakpoints, etc.
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
_This is a sass compiler plugin that uses the [functions](https://sass-lang.com/documentation/js-api/interfaces/options/#functions) option of the sass javascript api. Supports modern and legacy sass javascript api: `render`, `compile`, and `compileAsync`_
|
|
19
14
|
|
|
20
|
-
## Origin
|
|
15
|
+
## Origin/History
|
|
21
16
|
|
|
22
17
|
This module provides some of the asset functions that came with [Compass](http://compass-style.org). Originally a fork of [node-sass-asset-functions](https://github.com/fetch/node-sass-asset-functions) that was never merged.
|
|
23
18
|
|
|
@@ -78,6 +73,12 @@ All options are optional.
|
|
|
78
73
|
| `asset_host` | Function | Signature (http_path, callback(new_url)). Supply to perform url transform for `image-url` or `font-url`, presumably to define an asset host, but useful for any change to the url before the path |
|
|
79
74
|
| `data` | Object | An object of arbitrary data to reference at build-time. Defaults to `(empty)` |
|
|
80
75
|
|
|
76
|
+
### Advanced Options Quick Links
|
|
77
|
+
|
|
78
|
+
* **[Asset Cache Buster](#asset_cache_buster-a-function-to-rewrite-the-asset-path):** Modify URLs for cache busting (e.g., adding version numbers)
|
|
79
|
+
* **[Asset Host](#asset_host-a-function-which-completes-with-a-string-used-as-asset-host):** Set custom hostnames for assets
|
|
80
|
+
* **[Data Lookup](#lookup-a-function-to-use-arbitrary-data-in-sass-stylesheets):** Pass arbitrary data from JavaScript to Sass via the lookup() function
|
|
81
|
+
|
|
81
82
|
### Examples
|
|
82
83
|
|
|
83
84
|
You can specify the paths to your resources using the following options (shown with defaults):
|
|
@@ -85,10 +86,10 @@ You can specify the paths to your resources using the following options (shown w
|
|
|
85
86
|
```js
|
|
86
87
|
{
|
|
87
88
|
images_path: 'public/images', // local directory
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
http_fonts_path: '/fonts',
|
|
91
|
-
data: {}
|
|
89
|
+
http_images_path: '/images', // map to web path
|
|
90
|
+
fonts_path: 'public/fonts', // local directory
|
|
91
|
+
http_fonts_path: '/fonts', // map to web path
|
|
92
|
+
data: {} // build data exposed by *lookup*
|
|
92
93
|
}
|
|
93
94
|
```
|
|
94
95
|
|
|
@@ -100,27 +101,13 @@ const { default: assetFunctions } = require('@localnerve/sass-asset-functions');
|
|
|
100
101
|
|
|
101
102
|
const result = sass.compile(scss_filename, {
|
|
102
103
|
functions: assetFunctions({
|
|
103
|
-
images_path: 'public/img',
|
|
104
|
-
http_images_path: '/images'
|
|
104
|
+
images_path: 'public/img', // the local path to the assets
|
|
105
|
+
http_images_path: '/images' // the path from the browser to the assets
|
|
105
106
|
})
|
|
106
107
|
[, options...]
|
|
107
108
|
});
|
|
108
109
|
```
|
|
109
110
|
|
|
110
|
-
#### `sass`: Overriding the default compiler with Node-Sass
|
|
111
|
-
|
|
112
|
-
Example using the node-sass compiler using the new option `sass`.
|
|
113
|
-
|
|
114
|
-
```js
|
|
115
|
-
const sass = require('node-sass');
|
|
116
|
-
const { default: assetFunctions } = require('@localnerve/sass-asset-functions');
|
|
117
|
-
|
|
118
|
-
const result = sass.compile(scss_filename, {
|
|
119
|
-
functions: assetFunctions({ sass })
|
|
120
|
-
[, options...]
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
111
|
#### `lookup`: a function to use arbitrary data in sass stylesheets
|
|
125
112
|
|
|
126
113
|
This function retrieves arbitrary build-time data for reference in stylesheet compilation. Could be an asset name, prefix, or could be a whole list or map of things. Here's the list of javascript type mappings (everything else returns SassNull):
|
|
@@ -237,6 +224,22 @@ const result = sass.compileAsync(scss_filename, {
|
|
|
237
224
|
});
|
|
238
225
|
```
|
|
239
226
|
|
|
227
|
+
#### `sass`: Overriding the default compiler with Node-Sass
|
|
228
|
+
|
|
229
|
+
Example using the node-sass compiler using the new option `sass`.
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
const sass = require('node-sass');
|
|
233
|
+
const { default: assetFunctions } = require('@localnerve/sass-asset-functions');
|
|
234
|
+
|
|
235
|
+
const result = sass.compile(scss_filename, {
|
|
236
|
+
functions: assetFunctions({ sass })
|
|
237
|
+
[, options...]
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
_As of version 7.0.0, node-sass integration is no longer tested_
|
|
242
|
+
|
|
240
243
|
## Contributing
|
|
241
244
|
|
|
242
245
|
1. Fork it
|
|
@@ -244,3 +247,7 @@ const result = sass.compileAsync(scss_filename, {
|
|
|
244
247
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
245
248
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
246
249
|
5. Create new Pull Request
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
* [MIT](LICENSE.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localnerve/sass-asset-functions",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "compass-style asset functions for dart-sass or other sass compilers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"image-size": "^2.0.2",
|
|
55
55
|
"immutable": "^5.1.3",
|
|
56
56
|
"mime-types": "^3.0.1",
|
|
57
|
-
"sass": "^1.
|
|
57
|
+
"sass": "^1.92.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@babel/cli": "^7.28.3",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"eslint-plugin-jest": "^29.0.1",
|
|
65
65
|
"glob": "^11.0.3",
|
|
66
66
|
"globals": "^16.3.0",
|
|
67
|
-
"jest": "^30.1.
|
|
67
|
+
"jest": "^30.1.3",
|
|
68
68
|
"rimraf": "^6.0.1",
|
|
69
69
|
"tar": "^7.4.3"
|
|
70
70
|
},
|