Skip to content

Commit

Permalink
Merge pull request #402 from webpack-contrib/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
jhnns authored Mar 8, 2017
2 parents dcc432d + 9060e5b commit 5139fee
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ npm-debug.log
coverage
.idea
.nyc_output
test/output
14 changes: 14 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"reporter": [
"lcov",
"text"
],
"include": [
"lib/**/*.js"
],
"lines": 97,
"statements": 91,
"functions": 100,
"branches": 89,
"check-coverage": true
}
56 changes: 34 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[![npm-version][npm-version]][npm-url]
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![npm-stats][npm-stats]][npm-url]
[![deps][deps]][deps-url]
[![travis][travis]][travis-url]
[![coverage][coverage]][coverage-url]
[![appveyor][appveyor]][appveyor-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]

<div align="center">
<img height="100"
Expand Down Expand Up @@ -120,20 +123,6 @@ webpack provides an [advanced mechanism to resolve files](http://webpack.github.

It's important to only prepend it with `~`, because `~/` resolves to the home directory. webpack needs to distinguish between `bootstrap` and `~bootstrap` because CSS and Sass files have no special syntax for importing relative files. Writing `@import "file"` is the same as `@import "./file";`

### Environment variables

If you want to prepend Sass code before the actual entry file, you can simply set the `data` option. In this case, the sass-loader will not override the `data` option but just append the entry's content. This is especially useful when some of your Sass variables depend on the environment:

```javascript
{
loader: "sass-loader",
options: {
data: "$env: " + process.env.NODE_ENV + ";"
}
}
```


### Problems with `url(...)`

Since Sass/[libsass](https://github.com/sass/libsass) does not provide [url rewriting](https://github.com/sass/libsass/issues/532), all linked assets must be relative to the output.
Expand All @@ -146,11 +135,11 @@ More likely you will be disrupted by this second issue. It is natural to expect
- Add the missing url rewriting using the [resolve-url-loader](https://github.com/bholloway/resolve-url-loader). Place it directly after the sass-loader in the loader chain.
- Library authors usually provide a variable to modify the asset path. [bootstrap-sass](https://github.com/twbs/bootstrap-sass) for example has an `$icon-font-path`. Check out [this working bootstrap example](https://github.com/webpack-contrib/sass-loader/tree/master/test/bootstrapSass).

### Extracting stylesheets
### Extracting style sheets

Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or [hot module replacement](http://webpack.github.io/docs/hot-module-replacement-with-webpack.html) in development. In production, on the other hand, it's not a good idea to apply your stylesheets depending on JS execution. Rendering may be delayed or even a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible. Thus it's often still better to have them as separate files in your final production build.
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or [hot module replacement](https://webpack.js.org/concepts/hot-module-replacement/) in development. In production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution. Rendering may be delayed or even a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible. Thus it's often still better to have them as separate files in your final production build.

There are two possibilties to extract a stylesheet from the bundle:
There are two possibilities to extract a style sheet from the bundle:

- [extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
- [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) (more complex, but works in all use-cases)
Expand Down Expand Up @@ -184,6 +173,20 @@ module.exports = {

If you want to edit the original Sass files inside Chrome, [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0). Checkout [test/sourceMap](https://github.com/webpack-contrib/sass-loader/tree/master/test) for a running example.

### Environment variables

If you want to prepend Sass code before the actual entry file, you can set the `data` option. In this case, the sass-loader will not override the `data` option but just append the entry's content. This is especially useful when some of your Sass variables depend on the environment:

```javascript
{
loader: "sass-loader",
options: {
data: "$env: " + process.env.NODE_ENV + ";"
}
}
```

***Please note:** Since you're injecting code, this will break the source mappings in your entry file. Often there's a simpler solution than this, like multiple Sass entry files.**

## Maintainers

Expand Down Expand Up @@ -214,15 +217,24 @@ If you want to edit the original Sass files inside Chrome, [there's a good blog

[MIT](http://www.opensource.org/licenses/mit-license.php)

[npm-version]: https://img.shields.io/npm/v/sass-loader.svg
[npm]: https://img.shields.io/npm/v/sass-loader.svg
[npm-stats]: https://img.shields.io/npm/dm/sass-loader.svg
[npm-url]: https://npmjs.com/package/sass-loader

[node]: https://img.shields.io/node/v/sass-loader.svg
[node-url]: https://nodejs.org

[deps]: https://david-dm.org/webpack-contrib/sass-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/sass-loader

[travis]: http://img.shields.io/travis/webpack-contrib/sass-loader.svg
[travis-url]: https://travis-ci.org/webpack-contrib/sass-loader

[coverage]: https://img.shields.io/coveralls/webpack-contrib/sass-loader.svg
[coverage-url]: https://coveralls.io/r/webpack-contrib/sass-loader?branch=master
[appveyor-url]: https://ci.appveyor.com/project/jhnns/sass-loader/branch/master
[appveyor]: https://ci.appveyor.com/api/projects/status/github/webpack-contrib/sass-loader?svg=true

[cover]: https://coveralls.io/repos/github/webpack-contrib/sass-loader/badge.svg
[cover-url]: https://coveralls.io/github/webpack-contrib/sass-loader

[chat]: https://badges.gitter.im/webpack-contrib/webpack.svg
[chat-url]: https://gitter.im/webpack-contrib/webpack
29 changes: 29 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# appveyor file
# http://www.appveyor.com/docs/appveyor-yml

init:
- git config --global core.autocrlf input

# what combinations to test
environment:
matrix:
- nodejs_version: 7
job_part: test
- nodejs_version: 6
job_part: test
- nodejs_version: 4
job_part: test

install:
- ps: Install-Product node $env:nodejs_version x64
- npm install

build: off

matrix:
fast_finish: true

test_script:
- node --version
- npm --version
- cmd: npm run appveyor:%job_part%
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"main": "lib/loader.js",
"scripts": {
"create-spec": "node test/tools/runCreateSpec.js",
"pretest": "node test/tools/runCreateSpec.js",
"test": "mocha -R spec -t 10000",
"posttest": "eslint --fix lib test",
"pretest": "npm run create-spec",
"test": "nyc --all mocha -R spec -t 10000",
"posttest": "npm run lint",
"test-bootstrap-sass": "webpack-dev-server --config test/bootstrapSass/webpack.config.js --content-base ./test/bootstrapSass",
"test-source-map": "webpack-dev-server --config test/sourceMap/webpack.config.js --content-base ./test/sourceMap --inline",
"test-watch": "webpack --config test/watch/webpack.config.js",
"test-extract-text": "webpack --config test/extractText/webpack.config.js",
"test-hmr": "webpack-dev-server --config test/hmr/webpack.config.js --content-base ./test/hmr --hot --inline",
"coverage": "nyc --reporter=lcov npm test"
"lint": "eslint --ignore-path .gitignore lib test",
"appveyor:test": "npm test"
},
"keywords": [
"sass",
Expand All @@ -27,6 +28,9 @@
},
"author": "J. Tangelder",
"license": "MIT",
"engines": {
"node": ">=4.0.0"
},
"peerDependencies": {
"node-sass": "^4.0.0",
"webpack": "^2.0.0"
Expand Down
1 change: 0 additions & 1 deletion test/output/.gitignore

This file was deleted.

0 comments on commit 5139fee

Please sign in to comment.