Skip to content

Commit 78bd0a1

Browse files
authored
Update README.md (#987)
1 parent c049187 commit 78bd0a1

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Within your webpack configuration object, you'll need to add the babel-loader to
4141
module: {
4242
rules: [
4343
{
44-
test: /\.m?js$/,
44+
test: /\.(?:js|mjs|cjs)$/,
4545
exclude: /node_modules/,
4646
use: {
4747
loader: 'babel-loader',
@@ -66,7 +66,7 @@ You can pass options to the loader by using the [`options`](https://webpack.js.o
6666
module: {
6767
rules: [
6868
{
69-
test: /\.m?js$/,
69+
test: /\.(?:js|mjs|cjs)$/,
7070
exclude: /node_modules/,
7171
use: {
7272
loader: 'babel-loader',
@@ -106,13 +106,13 @@ You can also speed up babel-loader by as much as 2x by using the `cacheDirectory
106106

107107
### Some files in my node_modules are not transpiled for IE 11
108108

109-
Although we typically recommend not compiling `node_modules`, you may need to when using libraries that do not support IE 11.
109+
Although we typically recommend not compiling `node_modules`, you may need to when using libraries that do not support IE 11 or any legacy targets.
110110

111111
For this, you can either use a combination of `test` and `not`, or [pass a function](https://webpack.js.org/configuration/module/#condition) to your `exclude` option. You can also use negative lookahead regex as suggested [here](https://github.com/webpack/webpack/issues/2031#issuecomment-294706065).
112112

113113
```javascript
114114
{
115-
test: /\.m?js$/,
115+
test: /\.(?:js|mjs|cjs)$/,
116116
exclude: {
117117
and: [/node_modules/], // Exclude libraries in node_modules ...
118118
not: [
@@ -150,7 +150,7 @@ rules: [
150150
// the 'transform-runtime' plugin tells Babel to
151151
// require the runtime instead of inlining it.
152152
{
153-
test: /\.m?js$/,
153+
test: /\.(?:js|mjs|cjs)$/,
154154
exclude: /node_modules/,
155155
use: {
156156
loader: 'babel-loader',
@@ -216,7 +216,7 @@ require('./app');
216216
If you receive this message, it means that you have the npm package `babel` installed and are using the short notation of the loader in the webpack config (which is not valid anymore as of webpack 2.x):
217217
```javascript
218218
{
219-
test: /\.m?js$/,
219+
test: /\.(?:js|mjs|cjs)$/,
220220
loader: 'babel',
221221
}
222222
```
@@ -227,7 +227,7 @@ To fix this, you should uninstall the npm package `babel`, as it is deprecated i
227227
In the case one of your dependencies is installing `babel` and you cannot uninstall it yourself, use the complete name of the loader in the webpack config:
228228
```javascript
229229
{
230-
test: /\.m?js$/,
230+
test: /\.(?:js|mjs|cjs)$/,
231231
loader: 'babel-loader',
232232
}
233233
```

0 commit comments

Comments
 (0)