Skip to content

Commit bd4b9f8

Browse files
committed
Infra/babel index exports (#1980)
* babel main index file for lazy load exports * Update build script to write main entry in package.json
1 parent cbc4f95 commit bd4b9f8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"devDependencies": {
6262
"@babel/cli": "^7.16.8",
6363
"@babel/core": "^7.12.9",
64+
"@babel/plugin-transform-modules-commonjs": "^7.17.9",
6465
"@babel/preset-env": "^7.16.11",
6566
"@babel/preset-react": "^7.10.1",
6667
"@babel/runtime": "^7.12.5",

scripts/build.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const childProcess = require('child_process');
2+
const fs = require('fs');
23

34
const BABEL_OPTIONS = `--config-file ./src/.babelrc.json --extensions '.ts,.tsx' --ignore "src/**/*.d.ts"`;
5+
const BABEL_INDEX_EXPORTS_OPTIONS = `--config-file ./src/.babelrc.exports.js`;
46

57
console.info('## Start RNUILib Build ##');
68

@@ -13,7 +15,15 @@ childProcess.execSync(`./node_modules/.bin/babel src --out-dir src ${BABEL_OPTIO
1315
console.info('## Build lib (native component) files - convert TS to JS files ##');
1416
childProcess.execSync(`./node_modules/.bin/babel lib --out-dir lib ${BABEL_OPTIONS}`);
1517

18+
console.info('## Build main index file - for lazy load exports ##');
19+
childProcess.execSync(`./node_modules/.bin/babel ./src/index.js -o ./src/index.js ${BABEL_INDEX_EXPORTS_OPTIONS}`);
20+
1621
console.info('## Build standalone components packages ##');
1722
require('./buildPackages');
1823

24+
console.info('## Override package.json main entry to use src/index.js file ##');
25+
const package = JSON.parse(fs.readFileSync('./package.json'));
26+
package.main = 'src/index.js';
27+
fs.writeFileSync('./package.json', JSON.stringify(package, null, 2), {encoding: 'utf8'});
28+
1929
console.info('## Complete RNUILib Build ##');

src/.babelrc.exports.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: [
3+
['@babel/plugin-transform-modules-commonjs', {lazy: () => true}]
4+
],
5+
compact: false
6+
};

0 commit comments

Comments
 (0)