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