Skip to content

Commit 33eeb41

Browse files
gaearonTimer
authored andcommitted
Compile dependencies with babel-preset-env (facebook#3776)
1 parent ab6f23f commit 33eeb41

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

config/webpack.config.dev.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ module.exports = {
159159
name: 'static/media/[name].[hash:8].[ext]',
160160
},
161161
},
162-
// Process JS with Babel.
162+
// Process application JS with Babel.
163+
// The preset includes JSX, Flow, and some ESnext features.
163164
{
164165
test: /\.(js|jsx|mjs)$/,
165166
include: paths.appSrc,
@@ -175,6 +176,18 @@ module.exports = {
175176
cacheDirectory: true,
176177
},
177178
},
179+
// Process any JS outside of the app with Babel.
180+
// Unlike the application JS, we only compile the standard ES features.
181+
{
182+
test: /\.js$/,
183+
loader: require.resolve('babel-loader'),
184+
options: {
185+
babelrc: false,
186+
compact: false,
187+
presets: [require.resolve('babel-preset-react-app/dependencies')],
188+
cacheDirectory: true,
189+
},
190+
},
178191
// "postcss" loader applies autoprefixer to our CSS.
179192
// "css" loader resolves paths in CSS and adds assets as dependencies.
180193
// "style" loader turns CSS into JS modules that inject <style> tags.

config/webpack.config.prod.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ module.exports = {
167167
name: 'static/media/[name].[hash:8].[ext]',
168168
},
169169
},
170-
// Process JS with Babel.
170+
// Process application JS with Babel.
171+
// The preset includes JSX, Flow, and some ESnext features.
171172
{
172173
test: /\.(js|jsx|mjs)$/,
173174
include: paths.appSrc,
@@ -180,6 +181,18 @@ module.exports = {
180181
compact: true,
181182
},
182183
},
184+
// Process any JS outside of the app with Babel.
185+
// Unlike the application JS, we only compile the standard ES features.
186+
{
187+
test: /\.js$/,
188+
loader: require.resolve('babel-loader'),
189+
options: {
190+
babelrc: false,
191+
compact: false,
192+
presets: [require.resolve('babel-preset-react-app/dependencies')],
193+
cacheDirectory: true,
194+
},
195+
},
183196
// The notation here is somewhat confusing.
184197
// "postcss" loader applies autoprefixer to our CSS.
185198
// "css" loader resolves paths in CSS and adds assets as dependencies.

0 commit comments

Comments
 (0)