Skip to content

Commit 0ed0ef6

Browse files
committed
docs(readme): document that webpack 4.x users must write webpack.config in CommonJS format
1 parent cb29da5 commit 0ed0ef6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,44 @@ subdirectories. To enable this, set `includeNodeModules: true`.
103103

104104
Default: `false`.
105105

106+
## Webpack 4 Compatibility
107+
108+
This plugin supports webpack versions 4.x and 5.x. However, there are some
109+
caveats when using webpack 4.x in conjunction with ES modules.
110+
111+
Webpack 4.x does not support `webpack.config` files in ES module format, so if
112+
you set `"type": "module"` in `package.json` then you must mark the
113+
`webpack.config` file as a CommonJS file by naming it `webpack.config.cjs`
114+
(with a `.cjs` extension). Of course, you must also use CommonJS format, for
115+
example:
116+
117+
```js
118+
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin");
119+
120+
module.exports = {
121+
module: {
122+
rules: [
123+
{
124+
test: /\.tsx?$/,
125+
use: "ts-loader"
126+
}
127+
]
128+
},
129+
resolve: {
130+
plugins: [new ResolveTypeScriptPlugin()]
131+
}
132+
};
133+
```
134+
135+
Webpack 4.x also will not discover the `webpack.config` file automatically if
136+
it is named with a `.cjs` extension, so you must specify the path to the
137+
configuration file explicitly when running webpack, for example:
138+
`webpack --config ./webpack.config.cjs`.
139+
140+
Webpack 5.x has none of these caveats. In Webpack 5.x, configuration files may
141+
be in ES Module or CommonJS format, and will be discovered automatically if
142+
they are named with any of `.js`, `.cjs`, or `.mjs` file extensions.
143+
106144
## Feedback
107145

108146
We're seeking [community feedback][5] on this plugin.

0 commit comments

Comments
 (0)