Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/sass-resolve
Resolves all sass files in current project and all dependencies to create one sass file which includes them all.
https://github.com/thlorenz/sass-resolve
Last synced: 15 days ago
JSON representation
Resolves all sass files in current project and all dependencies to create one sass file which includes them all.
- Host: GitHub
- URL: https://github.com/thlorenz/sass-resolve
- Owner: thlorenz
- License: mit
- Created: 2013-10-29T19:47:37.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-01-27T01:16:36.000Z (almost 9 years ago)
- Last Synced: 2024-10-18T00:07:17.894Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 528 KB
- Stars: 26
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sass-resolve [![build status](https://secure.travis-ci.org/thlorenz/sass-resolve.png?branch=master)](http://travis-ci.org/thlorenz/sass-resolve)
Resolves all sass files in current project and all dependencies to create on sourcemapped css file from them.
```js
var sassResolve = require('sass-resolve');
var path = require('path');var projectPath = path.join(__dirname, 'fixtures');
sassResolve(
projectPath
, { inlineSourceMap: false }
, function (err, res) {
if (err) return console.error(err);
console.log(res.css);
console.log(res.map);
}
);
```## Installation
npm install sass-resolve
## Note
`sass-resolve >= v2` generates `css` using `libsass`. This eases deployment (`npm install` is all you need) and compiles
much faster (20x faster on our project) than `Ruby sass`.If you run into problems and need to use `Ruby sass`, please `npm install sass-resolve@1` and review the [relevant
docs](https://github.com/thlorenz/sass-resolve/blob/v1/README.md) (the API has changed somewhat).## API
### package.json
In order for resolve-sass to be able to find your `.scss` files you need to specify an `.scss` entry file via the
`main.scss` field in the `package.json` of each project that has `.scss` files.The entry `.scss` file should specify an `@import` for each `.scss` file you want to include.
#### Example
```json
// package.json
{
[..]
"main.scss": "sass/index.scss",
[..]
}
``````scss
// sass/index.scss
@import "foo";
@import "bar";
```Please investigate these [fixtures](https://github.com/thlorenz/sass-resolve/tree/master/test/fixtures) for more information.
To get a better understanding of what options to set, please consult [these
tests](https://github.com/thlorenz/sass-resolve/blob/master/test/sass-resolve.js).
sassResolve(root, opts, cb)Resolves paths to all .scss files from the current package and its dependencies.
The location of these sass files is indicated in the "main.scss" field inside packags.json.
It then generates the css file including all the rules found in the resolved .scss files.
Additionally it generates a .css.map file to enable sass source maps if so desired.Parameters:
Name
Type
Argument
Description
root
string
path to the current package
opts
Object
<optional>
configure if and how source maps are created and if a css file is written
Properties
Name
Type
Argument
Description
debug
boolean
<optional>
(default: true) generate source maps
inlineSourceMap
boolean
<optional>
(default: true) inline entire source map info into the .css file
instead of referring to an external .scss.map file
imports
function
<optional>
allows overriding how imports are resolved (see: resolveScssFiles and importsFromScssFiles)
mapFileName
string
<optional>
(default: 'transpiled.css.map') name of the source map file to be included
at the bottom of the generated css (not relevant when source maps are inlined)
cb
function
function (err, res]) {}, called when all scss files have been transpiled, when nowrite is true,
res contains generatedcss
andmap
(if sourcemaps were enabled and not inlined)
sassResolve::imports(root, cb)Resolves all paths of all .scss files of this project and its dependencies and
generates the sass imports for themParameters:
Name
Type
Description
root
String
full path to the project whose sass files to resolve
cb
function
called back with imports for the .scss files or an error if one occurred
sassResolve::resolveScssFiles(root, cb)Resolves paths to all .scss files from the current package and its dependencies.
The location of these sass files is indicated in the "main.scss" field inside packags.json.Parameters:
Name
Type
Description
root
String
full path to the project whose scss files to resolve
cb
function
called back with a list of paths to .scss files or an error if one occurred
sassResolve::scssFilesToImports(scssFiles) → {String}Creates a .scss import string from the previously resolved sass paths (see: resolveScssFiles)
This function is called byimports
and exposed as an advanced api if more manual tweaking is needed.Parameters:
Name
Type
Description
scssFiles
Array
paths to resolved
.scss
filesReturns:
of @import statements for each
.scss
file
Type
String*generated with [docme](https://github.com/thlorenz/docme)*
## Examples
### `debug: true, inlineSourceMap: false, mapFileName: 'my.css.map'`
Will generate source maps and inline the sources of all original files.
These source map is returned as `res.map` which you'll have to serve as `/my.css.map`.
### `debug: true, inlineSourceMap: true`
Will generate source maps and instead of referring to a separate `res.map`. all source map data is inlined at the bottom of the css.
Therefore you don't have to serve the source map, but keep in mind that now it adds to the size of the `css` loaded, so
only use this option in development.## License
MIT