mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-04 17:27:53 +08:00
[react-packager] Fix OOM
This commit is contained in:
@@ -59,7 +59,7 @@ function Transformer(options) {
|
||||
this._failedToStart = q.Promise.reject(new Error('No transfrom module'));
|
||||
} else {
|
||||
this._workers = workerFarm(
|
||||
{autoStart: true},
|
||||
{autoStart: true, maxConcurrentCallsPerWorker: 1},
|
||||
options.transformModulePath
|
||||
);
|
||||
}
|
||||
|
||||
25
packager/react-packager/src/Server/index.js
vendored
25
packager/react-packager/src/Server/index.js
vendored
@@ -8,6 +8,7 @@ var Packager = require('../Packager');
|
||||
var Activity = require('../Activity');
|
||||
var setImmediate = require('timers').setImmediate;
|
||||
var q = require('q');
|
||||
var _ = require('underscore');
|
||||
|
||||
module.exports = Server;
|
||||
|
||||
@@ -62,6 +63,12 @@ function Server(options) {
|
||||
|
||||
var onFileChange = this._onFileChange.bind(this);
|
||||
this._fileWatcher.on('all', onFileChange);
|
||||
|
||||
var self = this;
|
||||
this._debouncedFileChangeHandler = _.debounce(function(filePath) {
|
||||
self._rebuildPackages(filePath);
|
||||
self._informChangeWatchers();
|
||||
}, 50, true);
|
||||
}
|
||||
|
||||
Server.prototype._onFileChange = function(type, filepath, root) {
|
||||
@@ -69,8 +76,7 @@ Server.prototype._onFileChange = function(type, filepath, root) {
|
||||
this._packager.invalidateFile(absPath);
|
||||
// Make sure the file watcher event runs through the system before
|
||||
// we rebuild the packages.
|
||||
setImmediate(this._rebuildPackages.bind(this, absPath));
|
||||
setImmediate(this._informChangeWatchers.bind(this));
|
||||
this._debouncedFileChangeHandler(absPath);
|
||||
};
|
||||
|
||||
Server.prototype._rebuildPackages = function() {
|
||||
@@ -78,13 +84,16 @@ Server.prototype._rebuildPackages = function() {
|
||||
var packages = this._packages;
|
||||
Object.keys(packages).forEach(function(key) {
|
||||
var options = getOptionsFromUrl(key);
|
||||
packages[key] = buildPackage(options).then(function(p) {
|
||||
// Make a throwaway call to getSource to cache the source string.
|
||||
p.getSource({
|
||||
inlineSourceMap: options.dev,
|
||||
minify: options.minify,
|
||||
// Wait for a previous build (if exists) to finish.
|
||||
packages[key] = (packages[key] || q()).then(function() {
|
||||
return buildPackage(options).then(function(p) {
|
||||
// Make a throwaway call to getSource to cache the source string.
|
||||
p.getSource({
|
||||
inlineSourceMap: options.dev,
|
||||
minify: options.minify,
|
||||
});
|
||||
return p;
|
||||
});
|
||||
return p;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user