Skip to content

Commit 27856bf

Browse files
committed
1 parent d220da9 commit 27856bf

File tree

17 files changed

+404
-222
lines changed

17 files changed

+404
-222
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.*
33
!.babelrc
4+
yarn.lock

README.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,49 @@ Standalone ReactNative Packager without framework code.
99

1010
## Dependencies
1111

12-
```
12+
```json
1313
"devDependencies": {
1414
"rn-packager": "~0.9.0",
1515
"react-native": "0.34.1",
1616
"react": "~15.3.1"
1717
}
1818
```
19-
### Important:
19+
### Important:
2020
add `rn-blackliast.js` file at your project root dir for filter modules those your don't want package!
2121

2222
see the standard file at `lib/rn-blacklist.js`. your can add your common modules, support RegExp.
2323

2424
## Bundle
2525

26-
bundle without framework code and polyfill
27-
28-
```
29-
$ node_modules/rn-packager/bin/rnpackager bundle --entry-file entry/file/path.js --bundle-output out/file/path.jsbundle --platform ios
30-
```
26+
solution from https://github.com/facebook/react-native/pull/10804
3127

32-
added parameters:
28+
Now u can use `manifest.json` file to generate `core modules`.
3329

34-
* --include-framework Whether to bundle include module `react-native` and polyfills [default: false]
35-
* --runBeforeMainModule Modules required before main module [default: ["InitializeJavaScriptAppEngine"]]
30+
1. Bundle ur core bundle and output `manifest.json`
31+
2. Bundle ur app bundle with `manifest.json` that Step 1 generated.
3632

3733

38-
## Bundle sdk
34+
### Bundle core
3935

40-
```
41-
$ rnpackager bundle --entry-file node_modules/rn-core/react-native/Libraries/react-native/react-native.js --bundle-output ~/Desktop/react-native-debug.js --platform ios --include-framework
36+
```shell
37+
$ rnpackager bundle --entry-file node_modules/react-native/Libraries/react-native/react-native.js --bundle-output ~/Dowloads/core.ios.bundle --platform ios --manifest-output core.ios.manifest.json
4238
```
4339

44-
## Server
40+
### Bundle app
4541

46-
```
47-
$ rnpackager start
42+
```shell
43+
rnpackager bundle --entry-file foo.js --bundle-output ~/Dowloads/foo.ios.bundle --platform ios --manifest-file core.ios.manifest.json
4844
```
4945

50-
added query parameters: `framework=true` `runBeforeMainModule=[]`
46+
## Server
5147

52-
## Programmatic API
53-
```
54-
var RNPackager = require('rn-packager');
55-
56-
gulp.task('task', function(){
57-
return RNPackager.bundle.func({
58-
"entryFile": "tests/index.ios.js",
59-
"bundleOutput": "tests/index.ios.bundle",
60-
"platform": "ios"
61-
});
62-
});
48+
```shell
49+
$ rnpackager start
6350
```
6451

6552
## Demo
6653

67-
```
54+
```shell
6855
$ cd tests
6956
$ npm i
7057
$ rnpackager start

index.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-packager",
3-
"version": "0.9.7",
3+
"version": "0.9.8",
44
"description": "Based on Facebook Packager v0.32.0, support Core & Business JS Separate.",
55
"main": "src/index.js",
66
"bin": {

react-native/local-cli/bundle/buildBundle.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
// @Denis
11-
require('../../packager/babelRegisterOnly')([
12-
/react-packager\/src/
13-
]);
14-
1510
const log = require('../util/log').out('bundle');
1611
const outputBundle = require('./output/bundle');
1712
const path = require('path');
1813
const Promise = require('promise');
1914
const saveAssets = require('./saveAssets');
2015
const Server = require('../../packager/react-packager/src/Server');
16+
// @mc-zone
17+
const fs = require('fs');
2118
const defaultAssetExts = require('../../packager/defaultAssetExts');
2219

2320
function saveBundle(output, bundle, args) {
@@ -37,8 +34,6 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
3734
dev: args.dev,
3835
minify: !args.dev,
3936
platform: args.platform,
40-
runBeforeMainModule: args.runBeforeMainModule, // @Denis
41-
includeFramework: args.includeFramework, // @Denis
4237
};
4338

4439
// If a packager instance was not provided, then just create one for this
@@ -59,6 +54,12 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
5954
resetCache: args.resetCache,
6055
};
6156

57+
// @mc-zone
58+
if (typeof args.manifestFile === 'string') {
59+
options.manifestReferrence = JSON.parse(
60+
fs.readFileSync(args.manifestFile, 'utf-8')
61+
);
62+
}
6263
packagerInstance = new Server(options);
6364
shouldClosePackager = true;
6465
}

react-native/local-cli/bundle/bundle.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
// @Denis
11-
'use strict';
12-
13-
require('../../packager/babelRegisterOnly')([
14-
/local-cli/
15-
]);
16-
const defaultConfig = require('../default.config');
17-
1810
const buildBundle = require('./buildBundle');
1911
const outputBundle = require('./output/bundle');
2012
const outputPrepack = require('./output/prepack');
@@ -31,16 +23,6 @@ function bundleWithOutput(argv, config, args, output, packagerInstance) {
3123
}
3224

3325
function bundle(argv, config, args, packagerInstance) {
34-
// @Denis 支持构建脚本传入object参数
35-
if (isNaN(argv.length)) {
36-
config = config || defaultConfig;
37-
var args = argv;
38-
args.bundleEncoding = args.bundleEncoding || 'utf8';
39-
args.transformer = args.transformer || config.getTransformModulePath();
40-
}
41-
// console.log('argv:', argv);
42-
// console.log('config:', config);
43-
// console.log('args:', args);
4426
return bundleWithOutput(argv, config, args, undefined, packagerInstance);
4527
}
4628

react-native/local-cli/bundle/bundleCommandLineArgs.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ module.exports = [
5252
command: '--reset-cache',
5353
description: 'Removes cached files',
5454
default: false,
55-
}, { // @Denis 是否集成框架
56-
command: '--include-framework [boolean]',
57-
description: 'Whether to bundle include core modules and polyfills',
58-
default: false,
59-
}, { // @Denis 增加runBeforeMainModule
60-
command: '--runBeforeMainModule [string]',
61-
description: 'Modules required before main module',
62-
required: false,
55+
}, {
56+
// @mc-zone
57+
command: '--manifest-output [string]',
58+
description: 'File name where to store the manifest file for bundle splitting, ex. ./output/base.manifest.json',
59+
}, {
60+
command: '--manifest-file [path]',
61+
description: 'Path to the manifest file if want to split bundle, ex. ./output/base.manifest.json',
6362
},
6463
];

react-native/local-cli/bundle/output/bundle.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ function saveBundleAndMap(bundle, options, log) {
3131
bundleOutput,
3232
bundleEncoding: encoding,
3333
dev,
34-
sourcemapOutput
34+
sourcemapOutput,
35+
// @mc-zone
36+
manifestOutput,
3537
} = options;
3638

3739
log('start');
@@ -49,14 +51,35 @@ function saveBundleAndMap(bundle, options, log) {
4951
Promise.all([writeBundle, writeMetadata])
5052
.then(() => log('Done writing bundle output'));
5153

54+
// @mc-zone
55+
const writeTasks = [writeBundle];
56+
5257
if (sourcemapOutput) {
5358
log('Writing sourcemap output to:', sourcemapOutput);
5459
const writeMap = writeFile(sourcemapOutput, codeWithMap.map, null);
5560
writeMap.then(() => log('Done writing sourcemap output'));
56-
return Promise.all([writeBundle, writeMetadata, writeMap]);
57-
} else {
58-
return writeBundle;
61+
// @mc-zone
62+
// return Promise.all([writeBundle, writeMetadata, writeMap]);
63+
// } else {
64+
// return writeBundle;
65+
writeTasks.push(writeMetadata, writeMap);
66+
}
67+
68+
// @mc-zone
69+
if (manifestOutput) {
70+
log('Writing manifest output to:', manifestOutput);
71+
const manifest = createBundleManifest(bundle);
72+
const writeManifest = writeFile(manifestOutput, manifest, null);
73+
writeManifest.then(() => log('Done writing manifest output'));
74+
writeTasks.push(writeManifest);
5975
}
76+
77+
return Promise.all(writeTasks);
78+
}
79+
80+
// @mc-zone
81+
function createBundleManifest(bundle) {
82+
return JSON.stringify(bundle.getManifest(), null, 2);
6083
}
6184

6285
exports.build = buildBundle;

react-native/local-cli/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
require('./server/checkNodeVersion')();
1414

1515
require('../packager/babelRegisterOnly')([
16-
// /private-cli\/src/, @Denis
16+
/private-cli\/src/,
1717
/local-cli/,
1818
/react-packager\/src/
1919
]);

react-native/packager/blacklist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ var sharedBlacklist = [
2828
/rn-packager\/react-native\/local-cli\/.*/,
2929
'rn-packager/react-native/package.json',
3030
'rn-packager/react-native/packager/package.json',
31-
'react-native/Libraries/react-native/React.js',
32-
'react-native/Libraries/react-native/ReactNative.js',
31+
// 'react-native/Libraries/react-native/React.js',
32+
// 'react-native/Libraries/react-native/ReactNative.js',
3333
];
3434

3535
var platformBlacklists = {

0 commit comments

Comments
 (0)