https://github.com/gilbert/node-sass-endpoint
Easily server a SASS file from express.
https://github.com/gilbert/node-sass-endpoint
Last synced: 9 months ago
JSON representation
Easily server a SASS file from express.
- Host: GitHub
- URL: https://github.com/gilbert/node-sass-endpoint
- Owner: gilbert
- Created: 2015-09-25T22:33:41.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-01-23T23:09:35.000Z (over 7 years ago)
- Last Synced: 2025-09-11T09:45:00.223Z (10 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-sass-endpoint
Easily serve a SASS file as CSS from an express endpoint. No grunt/gulp, no build files, no required configuration – just pure data.
### Dependencies
- [node-sass](https://www.npmjs.com/package/node-sass) (taken care of by npm install)
- ES6 `Object.assign` (either use node v4.0+ or a [polyfill](https://www.npmjs.com/package/es6-object-assign))
### Installation
$ npm install node-sass-endpoint --save
## Usage - Easy Version
Assuming you have the following directory structure:
```
client/
├── app.scss
└── index.html
server/
└── index.js
package.json
```
Then you can write the following as your `server/index.js`:
```javascript
// server.js
var express = require('express');
var sass = require('node-sass-endpoint');
var app = express();
// Serve CSS
app.get('/assets/app-bundle.css',
sass.serve('./client/app.scss'));
// Serve HTML
var path = require('path')
app.get('/', function (req, res) {
res.sendFile( path.resolve(__dirname, '../client/public/admin.html') )
})
console.log("Listening on port 5555...");
app.listen(5555);
```
And run `node server/index.js`.
Now any GET request to `localhost:5555/assets/app-bundle.css` will compile and serve the SASS file located at `./client/app.scss`. Any `@import` statements within `app.scss` will also be included in the final output.
With that said, here is an example of using your sass-compiled CSS in `client/index.html`:
```html
```
## Advanced Usage
```javascript
app.get(
'/assets/app-bundle.css',
sass.serve('./client/app.scss', {
// (dev only) defaults to parent folder of scss file.
// Any sass file changes in this directory will clear the output cache.
watchDir: './client/',
// Defaults to parent folder of scss file.
// The node_modules/ is always included.
includePaths: ['./client/'],
// Defaults to "nested". Can be one of: "nested", "expanded", "compact", or "compressed".
outputStyle: 'compressed',
// Defaults to false
debug: false
})
);
```