Skip to content

Add support for complex config options #348

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

Closed
wants to merge 3 commits into from
Closed
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ module.exports = {
};
```

## Advanced options

If you need to pass [more advanced options](https://github.com/webpack/css-loader/pull/348), especially those which cannot be stringified, you can also define an `cssLoader`-property on your `webpack.config.js`:

``` javascript
module.exports = {
module: {
loaders: [{
test: /\.css$/,
loader: "style-loader!css-loader"
}]
},
cssLoader: {}
};
```

If you need to define two different loader configs, you can also change the config's property name via `css?config=otherCssLoaderConfig`:

``` javascript
module.exports = {
module: {
loaders: [{
test: /\.css$/,
loader: "style-loader!css-loader?config=otherCssLoaderConfig"
}]
},
otherCssLoaderConfig: {}
};
```

### 'Root-relative' urls

For urls that start with a `/`, the default behavior is to not translate them:
Expand Down
5 changes: 5 additions & 0 deletions lib/getLoaderConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var loaderUtils = require("loader-utils");

module.exports = function getLoaderConfig(loaderContext) {
return loaderUtils.getLoaderConfig(loaderContext, 'cssLoader') || {};
};
3 changes: 2 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ var loaderUtils = require("loader-utils");
var processCss = require("./processCss");
var getImportPrefix = require("./getImportPrefix");
var compileExports = require("./compile-exports");
var getLoaderConfig = require("./getLoaderConfig");


module.exports = function(content, map) {
if(this.cacheable) this.cacheable();
var callback = this.async();
var query = loaderUtils.parseQuery(this.query);
var query = getLoaderConfig(this);
var root = query.root;
var moduleMode = query.modules || query.module;
var camelCaseKeys = query.camelCase || query.camelcase;
Expand Down