Skip to content

Commit

Permalink
Merge pull request #4584 from relative-ci/virtual-modules-doc
Browse files Browse the repository at this point in the history
doc(webpack-plugin): How to exclude virtual modules
  • Loading branch information
vio authored Jul 20, 2024
2 parents 5e4e29d + 3b238f9 commit 4d1e763
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions packages/webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,44 @@ module.exports = {
- `stats` - [Webpack stats](https://webpack.js.org/configuration/stats) options
default:
```js
{
// webpack.config.js
module.exports = {
// ...
stats: {
assets: true,
chunks: true,
modules: true,
builtAt: true,
hash: true
}
}
hash: true,
},
};
```

[How to configure webpack for better debugging and monitoring](https://relative-ci.com/documentation/guides/webpack-config)

#### How to exclude virtual modules

Some plugins use virtual modules as an intermediary step when generating JS modules. For example, [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract) creates a virtual module for every `.css.js`/`css.ts` file based on the loader module path and the filename/source as query parameters:

```
./node_modules/@vanilla-extract/webpack-plugin/vanilla.virtual.css?%7B%22fileName%22%3A%22src%2Fcomponents%2Fcomponent%2Fcomponent.css.ts.vanilla.css%22%2C%22source%22%3A%22...%22%7D
```

Inlining the encoded source and the filename causes an increase in the size of the output stats and adds unnecessary entries to the stats. To ignore vanilla-extract virtual modules from the stats and from the bundle analysis report, use [`excludeModules`](https://webpack.js.org/configuration/stats/#statsexcludemodules) option:


```js
// webpack.config.js
module.exports = {
// ...
stats: {
excludeModules: [
/@vanilla-extract\/webpack-plugin\/vanilla-virtual\.css/,
],
},
};
```

### Use with create-react-app

You will need to customize the default webpack config. That can be done by using [react-app-rewired](https://github.com/timarney/react-app-rewired) which is one of create-react-app's custom config solutions. You will also need [customize-cra](https://github.com/arackaf/customize-cra).
Expand Down

0 comments on commit 4d1e763

Please sign in to comment.