From 6670e10b11ab0caded9e9b1888a5556950525348 Mon Sep 17 00:00:00 2001 From: xucong Date: Mon, 21 Nov 2022 18:07:55 +0800 Subject: [PATCH] fix: css loader options editable (#10) --- README.md | 6 +++++- src/index.js | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 517055f..fafbb69 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,14 @@ module.exports = withLess({ lessLoaderOptions: { /* ... */ }, + cssLoaderOptions: { + mode: 'pure', + /* ... */ + } }); ``` -You can see all the options available to `less-loader` [here](https://webpack.js.org/loaders/less-loader/#options). +You can see all the options available to `less-loader` [here](https://webpack.js.org/loaders/less-loader/#options). And you can see all the options available to `cssLoaderOptions` [here](https://github.com/webpack-contrib/css-loader#modules) ### Usage with [`next-compose-plugins`](https://github.com/cyrilwanner/next-compose-plugins) diff --git a/src/index.js b/src/index.js index 6e0cb52..e4b069d 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,7 @@ function patchNextCSSWithLess( patchNextCSSWithLess(); -function withLess({ lessLoaderOptions = {}, ...nextConfig }) { +function withLess({ lessLoaderOptions = {}, cssLoaderOptions = {}, ...nextConfig }) { return Object.assign({}, nextConfig, { /** * @param {import('webpack').Configuration} config @@ -73,6 +73,21 @@ function withLess({ lessLoaderOptions = {}, ...nextConfig }) { sassModuleRule = rule; } else if (rule.test?.source === "(? { + if( + moduleLoader.loader && + moduleLoader.loader.includes('css-loader') && + typeof moduleLoader.options?.modules === 'object' + ) { + moduleLoader.options.modules = { + ...moduleLoader.options.modules, + ...cssLoaderOptions + } + } + }) } });