mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-28 22:46:52 +08:00
Allow rn-cli.config.js to specify the default transformer
Summary: This will allow consumers to supply their own transformer to all `react-native` cli commands by simply implementing `rn-cli.config.js` and overriding `getTransformModulePath()`. That way they don't have to fork various parts of the iOS and Android build system that React Native already provides just to add a `--transformer` command line argument. **Test plan:** Applied this patch to the React Native version in my app, implemented `getTransformModulePath()` in my `rn-cli.config.js`, and verified that my custom transformer is invoked. Closes https://github.com/facebook/react-native/pull/7961 Differential Revision: D3404201 Pulled By: foghina fbshipit-source-id: c7eaa85de84d485d06d23a2ffea899821b2cf71c
This commit is contained in:
committed by
Facebook Github Bot 3
parent
9845f49581
commit
dd9b3e13a9
@@ -32,12 +32,16 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
|
||||
process.env.NODE_ENV = args.dev ? 'development' : 'production';
|
||||
}
|
||||
|
||||
const transformModulePath = args.transformer ?
|
||||
path.resolve(args.transformer) :
|
||||
config.getTransformModulePath();
|
||||
|
||||
const options = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
assetRoots: config.getAssetRoots(),
|
||||
blacklistRE: config.getBlacklistRE(args.platform),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: path.resolve(args.transformer),
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
nonPersistent: true,
|
||||
resetCache: args['reset-cache'],
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = [
|
||||
command: 'transformer',
|
||||
description: 'Specify a custom transformer to be used',
|
||||
type: 'string',
|
||||
default: require.resolve('../../packager/transformer'),
|
||||
default: null,
|
||||
}, {
|
||||
command: 'dev',
|
||||
description: 'If false, warnings are disabled and the bundle is minified',
|
||||
|
||||
@@ -30,7 +30,15 @@ var config = {
|
||||
*/
|
||||
getBlacklistRE(platform) {
|
||||
return blacklist(platform);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the path to a custom transformer. This can also be overridden
|
||||
* with the --transformer commandline argument.
|
||||
*/
|
||||
getTransformModulePath() {
|
||||
return require.resolve('../packager/transformer');
|
||||
},
|
||||
};
|
||||
|
||||
function getRoots() {
|
||||
|
||||
@@ -40,7 +40,7 @@ function _dependencies(argv, config, resolve, reject, packagerInstance) {
|
||||
}, {
|
||||
command: 'transformer',
|
||||
type: 'string',
|
||||
default: require.resolve('../../packager/transformer'),
|
||||
default: null,
|
||||
description: 'Specify a custom transformer to be used'
|
||||
}, {
|
||||
command: 'verbose',
|
||||
@@ -54,12 +54,16 @@ function _dependencies(argv, config, resolve, reject, packagerInstance) {
|
||||
reject(`File ${rootModuleAbsolutePath} does not exist`);
|
||||
}
|
||||
|
||||
const transformModulePath = args.transformer ?
|
||||
path.resolve(args.transformer) :
|
||||
config.getTransformModulePath();
|
||||
|
||||
const packageOpts = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
assetRoots: config.getAssetRoots(),
|
||||
blacklistRE: config.getBlacklistRE(args.platform),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: path.resolve(args.transformer),
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
verbose: config.verbose,
|
||||
};
|
||||
|
||||
@@ -67,13 +67,17 @@ function runServer(args, config, readyCallback) {
|
||||
}
|
||||
|
||||
function getPackagerServer(args, config) {
|
||||
const transformModulePath = args.transformer ?
|
||||
path.resolve(args.transformer) :
|
||||
config.getTransformModulePath();
|
||||
|
||||
return ReactPackager.createServer({
|
||||
nonPersistent: args.nonPersistent,
|
||||
projectRoots: args.projectRoots,
|
||||
blacklistRE: config.getBlacklistRE(),
|
||||
cacheVersion: '3',
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: path.resolve(args.transformer),
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
assetRoots: args.assetRoots,
|
||||
assetExts: [
|
||||
|
||||
@@ -54,7 +54,7 @@ function _server(argv, config, resolve, reject) {
|
||||
}, {
|
||||
command: 'transformer',
|
||||
type: 'string',
|
||||
default: require.resolve('../../packager/transformer'),
|
||||
default: null,
|
||||
description: 'Specify a custom transformer to be used'
|
||||
}, {
|
||||
command: 'resetCache',
|
||||
|
||||
@@ -33,4 +33,9 @@ module.exports = {
|
||||
return [path.resolve(__dirname, '..')];
|
||||
}
|
||||
},
|
||||
|
||||
getTransformModulePath() {
|
||||
return require.resolve('./transformer');
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user