-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use the bob preset for the library during dev (#599)
Previously the React Native Babel preset was being used t compile the library code as well. However, this preset differs from the preset used to publish the library which can introduce inconsistencies. For example, Metro compiles modules in loose mode which can hide strict mode errors during dev, but they'll surface when consumer uses the library. With this change, we make sure that the same preset is used for dev to avoid the inconsistency. It also adds a babel plugin to explicitly add `use strict` - as Metro doesn't use strict mode for ESM code which is not spec-compliant, and the behavior differs from the CommonJS build where we add `use strict` during publish.
- Loading branch information
Showing
8 changed files
with
86 additions
and
43 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
4 changes: 3 additions & 1 deletion
4
packages/create-react-native-library/templates/common/babel.config.js
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module.exports = { | ||
presets: ['module:@react-native/babel-preset'], | ||
presets: [ | ||
['module:react-native-builder-bob/babel-preset', { modules: 'commonjs' }], | ||
], | ||
}; |
42 changes: 30 additions & 12 deletions
42
packages/create-react-native-library/templates/expo-library/example/babel.config.js
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 |
---|---|---|
@@ -1,22 +1,40 @@ | ||
const path = require('path'); | ||
const pak = require('../package.json'); | ||
|
||
const root = path.resolve(__dirname, '..'); | ||
|
||
module.exports = function (api) { | ||
api.cache(true); | ||
|
||
return { | ||
presets: ['babel-preset-expo'], | ||
plugins: [ | ||
[ | ||
'module-resolver', | ||
{ | ||
extensions: ['.tsx', '.ts', '.js', '.json'], | ||
alias: { | ||
// For development, we want to alias the library to the source | ||
[pak.name]: path.join(__dirname, '..', pak.source), | ||
}, | ||
}, | ||
], | ||
overrides: [ | ||
{ | ||
exclude: path.join(root, 'src'), | ||
presets: ['babel-preset-expo'], | ||
}, | ||
{ | ||
include: path.join(root, 'src'), | ||
presets: [ | ||
[ | ||
'module:react-native-builder-bob/babel-preset', | ||
{ modules: 'commonjs' }, | ||
], | ||
], | ||
}, | ||
{ | ||
exclude: /\/node_modules\//, | ||
plugins: [ | ||
[ | ||
'module-resolver', | ||
{ | ||
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'], | ||
alias: { | ||
[pak.name]: path.join(root, pak.source), | ||
}, | ||
}, | ||
], | ||
], | ||
}, | ||
], | ||
}; | ||
}; |
41 changes: 30 additions & 11 deletions
41
packages/create-react-native-library/templates/native-common-example/example/babel.config.js
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 |
---|---|---|
@@ -1,17 +1,36 @@ | ||
const path = require('path'); | ||
const pak = require('../package.json'); | ||
|
||
const root = path.resolve(__dirname, '..'); | ||
|
||
module.exports = { | ||
presets: ['module:@react-native/babel-preset'], | ||
plugins: [ | ||
[ | ||
'module-resolver', | ||
{ | ||
extensions: ['.tsx', '.ts', '.js', '.json'], | ||
alias: { | ||
[pak.name]: path.join(__dirname, '..', pak.source), | ||
}, | ||
}, | ||
], | ||
overrides: [ | ||
{ | ||
exclude: path.join(root, 'src'), | ||
presets: ['module:@react-native/babel-preset'], | ||
}, | ||
{ | ||
include: path.join(root, 'src'), | ||
presets: [ | ||
[ | ||
'module:react-native-builder-bob/babel-preset', | ||
{ modules: 'commonjs' }, | ||
], | ||
], | ||
}, | ||
{ | ||
exclude: /\/node_modules\//, | ||
plugins: [ | ||
[ | ||
'module-resolver', | ||
{ | ||
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'], | ||
alias: { | ||
[pak.name]: path.join(root, pak.source), | ||
}, | ||
}, | ||
], | ||
], | ||
}, | ||
], | ||
}; |
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