Skip to content

Commit

Permalink
fix: css loader options editable (elado#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuerzong committed Nov 21, 2022
1 parent 271cc74 commit b0bcde3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +73,21 @@ function withLess({ lessLoaderOptions = {}, ...nextConfig }) {
sassModuleRule = rule;
} else if (rule.test?.source === "(?<!\\.module)\\.(scss|sass)$") {
sassGlobalRule = rule;
}

if(Array.isArray(rule.use)) {
rule.use.forEach(moduleLoader => {
if(
moduleLoader.loader &&
moduleLoader.loader.includes('css-loader') &&
typeof moduleLoader.options?.modules === 'object'
) {
moduleLoader.options.modules = {
...moduleLoader.options.modules,
...cssLoaderOptions
}
}
})
}
});

Expand Down

0 comments on commit b0bcde3

Please sign in to comment.