Make metro-bundler use a no-op transformer by default

Summary: When starting to use `metro-bundler` as a standalone server, I found quite complicated the fact that it needs a transformer by default. Moreover, the transformer is not passed as a reference to a JS object, but as a path to a required file. I removed the need to be required, and defaulted to a dummy, basic transform, that does nothing by default. This avoids having to create an extra file and linking to it (potentially needing to involve `path` and other extra modules).

Reviewed By: cpojer

Differential Revision: D5622906

fbshipit-source-id: 0c2b1bec86fa542b3c05de42c89d4b5bb4384b34
This commit is contained in:
Miguel Jimenez Esun 2017-08-29 09:21:40 -07:00 committed by Facebook Github Bot
parent 3731fa7c3c
commit 84ae805e78
3 changed files with 18 additions and 2 deletions

View File

@ -91,7 +91,7 @@ export type Options = {|
silent?: boolean,
+sourceExts: ?Array<string>,
+transformCache: TransformCache,
+transformModulePath: string,
transformModulePath?: string,
watch?: boolean,
workerPath: ?string,
|};
@ -214,7 +214,8 @@ class Server {
silent: options.silent || false,
sourceExts: options.sourceExts || defaults.sourceExts,
transformCache: options.transformCache,
transformModulePath: options.transformModulePath,
transformModulePath:
options.transformModulePath || defaults.transformModulePath,
watch: options.watch || false,
workerPath: options.workerPath,
};

View File

@ -0,0 +1,13 @@
/**
* 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.
*
* @flow
*/
'use strict';
module.exports.transform = (file: {src: string}) => ({code: file.src});

View File

@ -29,6 +29,8 @@ exports.providesModuleNodeModules = [
'react-native-windows',
];
exports.transformModulePath = require.resolve('./defaultTransform.js');
exports.runBeforeMainModule = [
// Ensures essential globals are available and are patched correctly.
'InitializeCore',