-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Switch back to babel-loader #5143
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c92efca
Switch back to babel-loader
iansu fcfecca
Preserve existing caller options. Use Object.assign instead of object…
iansu 0b6ca8a
Updated filename in package.json
iansu 95dc224
Update comment about cache identifier
iansu a9f10a1
Update macro check to use a regex
iansu d3bc770
Move macro check regex out of function
iansu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 add a random token | ||
// to the caller, 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) { | ||
return Object.assign({}, config.options, { | ||
caller: Object.assign({}, config.options.caller, { | ||
craInvalidationToken: crypto.randomBytes(32).toString('hex'), | ||
}), | ||
}); | ||
} | ||
return config.options; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: you can do one lookup for just
macro
.Then check the character at previous index.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
At that point, we might as well just look for
macro
. If the previous character wasn't.
or/
, we'd probably want to search again -- nullifying any performance gain.Though, 9/10 times we'd probably see that
.
or/
character and get to bail out early.FWIW,
indexOf
appears to be extremely fast: https://jsperf.com/test-indexof-vs-includesThis only needs to be ran once on a file that doesn't include macros.
(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 comment
The 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 comment
The 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 comment
The 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 comment
The 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 comment
The 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.
https://koukia.ca/top-6-ways-to-search-for-a-string-in-javascript-and-performance-benchmarks-ce3e9b81ad31#---0-21
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 comment
The 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 comment
The 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.