forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent the cache of files using Babel Macros (facebook#5078)
* Add new overrides option * Add file to package.json * Create our own loader * Remove overrides * We have to use a real babel option * Add comments
- Loading branch information
Showing
6 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
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,12 @@ | ||
/** | ||
* 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 loader = require('babel-loader'); | ||
const overrides = require('./overrides'); | ||
|
||
module.exports = loader.custom(() => overrides); |
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,32 @@ | ||
/** | ||
* 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 = { | ||
// 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) { | ||
return { | ||
...config.options, | ||
caller: { | ||
name: `babel-preset-react-app:${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