From c134a843c8d9b0f0c57ad739c66ca7d5e0572c11 Mon Sep 17 00:00:00 2001 From: Marat Dreizin Date: Wed, 28 Sep 2016 14:18:17 +0300 Subject: [PATCH 1/2] added ability to use custom loader options via "config" loader query --- lib/getLoaderConfig.js | 5 +++++ lib/loader.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/getLoaderConfig.js diff --git a/lib/getLoaderConfig.js b/lib/getLoaderConfig.js new file mode 100644 index 00000000..7bab8473 --- /dev/null +++ b/lib/getLoaderConfig.js @@ -0,0 +1,5 @@ +var loaderUtils = require("loader-utils"); + +module.exports = function getLoaderConfig(loaderContext) { + return loaderUtils.getLoaderConfig(loaderContext, 'cssLoader') || {}; +}; diff --git a/lib/loader.js b/lib/loader.js index f4d0d98e..6a56fb11 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -6,12 +6,13 @@ var path = require("path"); var loaderUtils = require("loader-utils"); var processCss = require("./processCss"); var getImportPrefix = require("./getImportPrefix"); +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; From be53c18ad04e7ecf396eee4cbf5417d97d1843ec Mon Sep 17 00:00:00 2001 From: Marat Dreizin Date: Wed, 28 Sep 2016 14:42:04 +0300 Subject: [PATCH 2/2] added missing documentation --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 676fb3f0..2521245b 100644 --- a/README.md +++ b/README.md @@ -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: