-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Switch back to babel-loader #5143
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
Changes from 2 commits
c92efca
fcfecca
0b6ca8a
95dc224
a9f10a1
d3bc770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
const crypto = require('crypto'); | ||
|
||
module.exports = function() { | ||
return { | ||
// This function transforms the Babel configuration on a per-file basis | ||
config(config, { source }) { | ||
// Babel Macros are notoriously hard to cache, so they shouldn't be | ||
// https://github.com/babel/babel/issues/8497 | ||
// We naively detect macros using their package suffix and insert a random | ||
// caller name, a valid option accepted by Babel, to compose a one-time | ||
// cacheIdentifier for the file. We cannot tune the loader options on a per | ||
// file basis. | ||
if (source.indexOf('.macro') !== -1 || source.indexOf('/macro') !== -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you can do one lookup for just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make that work we'd have to save the index into a variable. Is that tradeoff worth it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At that point, we might as well just look for FWIW, (I'm sure it's way slower on a large file, but faster than babel parsing it!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume regex would be way slower? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you mean? There's no real cost for putting it into a variable in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It depends. Regex can actually be faster. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just mean the cost of both seems quite low so is it worth trading one for the other? I think the way it is currently it's easy to read and understand what's going on. I think it gets a bit more complicated/less clear if we change the algorithm (see @Timer's comment above). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Timer I would assume regex would be slower too but then I started to second guess that. Maybe doing both checks in one go with a regex would be fastest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with using a regex. I disagree re: the cost being low. That's how you get to slow builds, one small decision at a time. If it's a hot path (which it is for cold builds) let's put in some effort to avoid doing the same work twice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meh. Whatever. I'm just being grumpy. It probably doesn't matter at this scale. Things like this tend to matter in React but this is not React. |
||
return Object.assign({}, config.options, { | ||
caller: Object.assign({}, config.options.caller, { | ||
craInvalidationToken: crypto.randomBytes(32).toString('hex'), | ||
}), | ||
}); | ||
} | ||
return config.options; | ||
}, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,8 +272,11 @@ module.exports = { | |
// We need to use our own loader until `babel-loader` supports | ||
// customization | ||
// https://github.com/babel/babel-loader/pull/687 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment needs deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Removed in 232e892. |
||
loader: require.resolve('babel-preset-react-app/loader'), | ||
loader: require.resolve('babel-loader'), | ||
options: { | ||
customize: require.resolve( | ||
'babel-preset-react-app/webpack-overrides' | ||
), | ||
// @remove-on-eject-begin | ||
babelrc: false, | ||
configFile: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: update comment to reflect the move from modifying the name to adding craInvalidationToken