You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add trouble shooting about how to transpile node_modules (#883)
* Add trouble shooting about how to transpile node_modules
* Apply suggestions from code review
Co-authored-by: Brian Ng <[email protected]>
* Update README.md
Co-authored-by: Nicolò Ribaudo <[email protected]>
* Apply suggestions from code review
Co-authored-by: Brian Ng <[email protected]>
Co-authored-by: Brian Ng <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
@@ -94,6 +98,35 @@ To exclude `node_modules`, see the `exclude` option in the `loaders` config as d
94
98
95
99
You can also speed up babel-loader by as much as 2x by using the `cacheDirectory` option. This will cache transformations to the filesystem.
96
100
101
+
### Some files in my node_modules are not transpiled for IE 11
102
+
103
+
Although we typically recommend not compiling `node_modules`, you may need to when using libraries that do not support IE 11.
104
+
105
+
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).
106
+
107
+
```javascript
108
+
{
109
+
test:/\.m?js$/,
110
+
exclude: {
111
+
test:/node_modules/, // Exclude libraries in node_modules ...
112
+
not: [
113
+
// Except for a few of them that needs to be transpiled because they use modern syntax
114
+
/unfetch/,
115
+
/d3-array|d3-scale/,
116
+
/@hapi[\\/]joi-date/,
117
+
]
118
+
},
119
+
use: {
120
+
loader:'babel-loader',
121
+
options: {
122
+
presets: [
123
+
['@babel/preset-env', { targets:"ie 11" }]
124
+
]
125
+
}
126
+
}
127
+
}
128
+
```
129
+
97
130
### Babel is injecting helpers into each file and bloating my code!
98
131
99
132
Babel uses very small helpers for common functions such as `_extend`. By default, this will be added to every file that requires it.
@@ -112,11 +145,13 @@ rules: [
112
145
// require the runtime instead of inlining it.
113
146
{
114
147
test:/\.m?js$/,
115
-
exclude:/(node_modules|bower_components)/,
148
+
exclude:/node_modules/,
116
149
use: {
117
150
loader:'babel-loader',
118
151
options: {
119
-
presets: ['@babel/preset-env'],
152
+
presets: [
153
+
['@babel/preset-env', { targets:"defaults" }]
154
+
],
120
155
plugins: ['@babel/plugin-transform-runtime']
121
156
}
122
157
}
@@ -202,9 +237,9 @@ You will need to exclude them form `babel-loader`.
0 commit comments