Skip to content

Commit 4d1e763

Browse files
authored
Merge pull request #4584 from relative-ci/virtual-modules-doc
doc(webpack-plugin): How to exclude virtual modules
2 parents 5e4e29d + 3b238f9 commit 4d1e763

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

packages/webpack-plugin/README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,44 @@ module.exports = {
7676
- `stats` - [Webpack stats](https://webpack.js.org/configuration/stats) options
7777
default:
7878
```js
79-
{
79+
// webpack.config.js
80+
module.exports = {
81+
// ...
8082
stats: {
8183
assets: true,
8284
chunks: true,
8385
modules: true,
8486
builtAt: true,
85-
hash: true
86-
}
87-
}
87+
hash: true,
88+
},
89+
};
8890
```
8991

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

94+
#### How to exclude virtual modules
95+
96+
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:
97+
98+
```
99+
./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
100+
```
101+
102+
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:
103+
104+
105+
```js
106+
// webpack.config.js
107+
module.exports = {
108+
// ...
109+
stats: {
110+
excludeModules: [
111+
/@vanilla-extract\/webpack-plugin\/vanilla-virtual\.css/,
112+
],
113+
},
114+
};
115+
```
116+
92117
### Use with create-react-app
93118

94119
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).

0 commit comments

Comments
 (0)