mirror of https://github.com/status-im/metro.git
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:
parent
da27090d83
commit
62a3d2c843
|
@ -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;
|
|
@ -9,13 +9,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var babel = require('babel-core');
|
var babel = require('babel-core');
|
||||||
|
var resolvePlugins = require('./resolvePlugins');
|
||||||
var Transforms = require('../transforms');
|
var Transforms = require('../transforms');
|
||||||
|
|
||||||
// Runs internal transforms on the given sourceCode. Note that internal
|
// Runs internal transforms on the given sourceCode. Note that internal
|
||||||
// transforms should be run after the external ones to ensure that they run on
|
// transforms should be run after the external ones to ensure that they run on
|
||||||
// Javascript code
|
// Javascript code
|
||||||
function internalTransforms(sourceCode, filename, options) {
|
function internalTransforms(sourceCode, filename, options) {
|
||||||
var plugins = Transforms.getAll(options);
|
var plugins = resolvePlugins(Transforms.getAll(options));
|
||||||
if (plugins.length === 0) {
|
if (plugins.length === 0) {
|
||||||
return {
|
return {
|
||||||
code: sourceCode,
|
code: sourceCode,
|
||||||
|
|
|
@ -16,6 +16,7 @@ const inlineRequires = require('fbjs-scripts/babel-6/inline-requires');
|
||||||
const json5 = require('json5');
|
const json5 = require('json5');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const ReactPackager = require('./react-packager');
|
const ReactPackager = require('./react-packager');
|
||||||
|
const resolvePlugins = require('./react-packager/src/JSTransformer/resolvePlugins');
|
||||||
|
|
||||||
const babelRC =
|
const babelRC =
|
||||||
json5.parse(
|
json5.parse(
|
||||||
|
@ -36,23 +37,7 @@ function transform(src, filename, options) {
|
||||||
if (options.inlineRequires) {
|
if (options.inlineRequires) {
|
||||||
extraPlugins.push(inlineRequires);
|
extraPlugins.push(inlineRequires);
|
||||||
}
|
}
|
||||||
config.plugins = extraPlugins.concat(config.plugins);
|
config.plugins = resolvePlugins(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;
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = babel.transform(src, Object.assign({}, babelRC, config));
|
const result = babel.transform(src, Object.assign({}, babelRC, config));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue