Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target specific node modules with babel. #3566

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ const publicPath = '/';
const publicUrl = '';
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);

// Application package.json
const pkg = require(paths.appPackageJson);
// An array property in the apps package.json called "transpileDependencies"
const transpileModules = pkg.transpileDependencies || [];
// The list of packages in node_modules that babel will include in it's transpile.
const babelInclude = [
paths.appSrc,
...transpileModules.map(m => path.resolve(paths.appNodeModules, m)),
];
// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
Expand Down Expand Up @@ -163,7 +171,7 @@ module.exports = {
// Process JS with Babel.
{
test: /\.(js|jsx|mjs)$/,
include: paths.appSrc,
include: babelInclude,
loader: require.resolve('babel-loader'),
options: {
// @remove-on-eject-begin
Expand Down
11 changes: 10 additions & 1 deletion packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
const publicUrl = publicPath.slice(0, -1);
// Get environment variables to inject into our app.
const env = getClientEnvironment(publicUrl);
// Application package.json
const pkg = require(paths.appPackageJson);
// An array property in the apps package.json called "transpileDependencies"
const transpileModules = pkg.transpileDependencies || [];
// The list of packages in node_modules that babel will include in it's transpile.
const babelInclude = [
paths.appSrc,
...transpileModules.map(m => path.resolve(paths.appNodeModules, m)),
];

// Assert this just to be safe.
// Development builds of React are slow and not intended for production.
Expand Down Expand Up @@ -170,7 +179,7 @@ module.exports = {
// Process JS with Babel.
{
test: /\.(js|jsx|mjs)$/,
include: paths.appSrc,
include: babelInclude,
loader: require.resolve('babel-loader'),
options: {
// @remove-on-eject-begin
Expand Down