Skip to content

Commit

Permalink
Allow overriding Webpack module rules (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 committed Aug 1, 2023
1 parent 321cce2 commit a044864
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .changeset/tidy-cows-complain.md
@@ -0,0 +1,23 @@
---
'playroom': patch
---

Allow overriding Webpack module rules

Consumers may have complex Webpack configurations that can clash with Playroom's.
In this case, it's useful to be able to override the module rules that Playroom defines.
For example, overriding loaders defined for CSS files:

```js
// playroom.config.js
module.exports = {
webpackConfig: () => ({
module: {
rules: [
// use your own CSS loaders
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
],
},
}),
};
```
13 changes: 11 additions & 2 deletions lib/makeWebpackConfig.js
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const { mergeWithRules } = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('@soda/friendly-errors-webpack-plugin');
const getStaticTypes = require('./getStaticTypes');
Expand Down Expand Up @@ -199,5 +199,14 @@ module.exports = async (playroomConfig, options) => {
? await playroomConfig.webpackConfig()
: makeDefaultWebpackConfig(playroomConfig);

return merge(ourConfig, theirConfig);
const mergedConfig = mergeWithRules({
module: {
rules: {
test: 'match',
use: 'replace',
},
},
})(ourConfig, theirConfig);

return mergedConfig;
};

0 comments on commit a044864

Please sign in to comment.