Make Hot Loading work on OSS

Summary:
public

- Tweak OSS server to enable the HMR connection
- Remove client gating code.
- Resolve internal transforms plugins

After this diff, Hot Loading should work on OSS.

Reviewed By: javache

Differential Revision: D2803620

fb-gh-sync-id: b678180c884d2bfaf454edf9e7abe6b3b3b32ebe
This commit is contained in:
Martín Bigio 2016-01-14 19:32:17 -08:00 committed by facebook-github-bot-9
parent da27090d83
commit 62a3d2c843
3 changed files with 36 additions and 18 deletions

View File

@ -0,0 +1,32 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/**
* Manually resolve all default Babel plugins.
* `babel.transform` will attempt to resolve all base plugins relative to
* the file it's compiling. This makes sure that we're using the plugins
* installed in the react-native package.
*/
function resolvePlugins(plugins) {
return plugins.map(function(plugin) {
// Normalise plugin to an array.
if (!Array.isArray(plugin)) {
plugin = [plugin];
}
// Only resolve the plugin if it's a string reference.
if (typeof plugin[0] === 'string') {
plugin[0] = require('babel-plugin-' + plugin[0]);
plugin[0] = plugin[0].__esModule ? plugin[0].default : plugin[0];
}
return plugin;
});
}
module.exports = resolvePlugins;

View File

@ -9,13 +9,14 @@
'use strict';
var babel = require('babel-core');
var resolvePlugins = require('./resolvePlugins');
var Transforms = require('../transforms');
// Runs internal transforms on the given sourceCode. Note that internal
// transforms should be run after the external ones to ensure that they run on
// Javascript code
function internalTransforms(sourceCode, filename, options) {
var plugins = Transforms.getAll(options);
var plugins = resolvePlugins(Transforms.getAll(options));
if (plugins.length === 0) {
return {
code: sourceCode,

View File

@ -16,6 +16,7 @@ const inlineRequires = require('fbjs-scripts/babel-6/inline-requires');
const json5 = require('json5');
const path = require('path');
const ReactPackager = require('./react-packager');
const resolvePlugins = require('./react-packager/src/JSTransformer/resolvePlugins');
const babelRC =
json5.parse(
@ -36,23 +37,7 @@ function transform(src, filename, options) {
if (options.inlineRequires) {
extraPlugins.push(inlineRequires);
}
config.plugins = extraPlugins.concat(config.plugins);
// Manually resolve all default Babel plugins. babel.transform will attempt to resolve
// all base plugins relative to the file it's compiling. This makes sure that we're
// using the plugins installed in the react-native package.
config.plugins = config.plugins.map(function(plugin) {
// Normalise plugin to an array.
if (!Array.isArray(plugin)) {
plugin = [plugin];
}
// Only resolve the plugin if it's a string reference.
if (typeof plugin[0] === 'string') {
plugin[0] = require(`babel-plugin-${plugin[0]}`);
plugin[0] = plugin[0].__esModule ? plugin[0].default : plugin[0];
}
return plugin;
});
config.plugins = resolvePlugins(extraPlugins.concat(config.plugins));
const result = babel.transform(src, Object.assign({}, babelRC, config));