mirror of https://github.com/status-im/metro.git
xplat/js: replace import() calls by require.async() calls
Reviewed By: mjesun Differential Revision: D6147316 fbshipit-source-id: b93a247ce0830a5db250824d22e81a3b786daf36
This commit is contained in:
parent
d01f514fa0
commit
e4dad595e1
|
@ -33,14 +33,16 @@ export type TransformedCode = {
|
||||||
map?: ?MappingsMap,
|
map?: ?MappingsMap,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Transformer<ExtraOptions: {} = {}> = {
|
export type Transform<ExtraOptions: {}> = ({|
|
||||||
transform: ({|
|
|
||||||
filename: string,
|
filename: string,
|
||||||
localPath: string,
|
localPath: string,
|
||||||
options: ExtraOptions & TransformOptions,
|
options: ExtraOptions & TransformOptions,
|
||||||
plugins?: BabelPlugins,
|
plugins?: BabelPlugins,
|
||||||
src: string,
|
src: string,
|
||||||
|}) => {ast: ?Ast, code: string, map: ?MappingsMap},
|
|}) => {ast: ?Ast, code: string, map: ?MappingsMap};
|
||||||
|
|
||||||
|
export type Transformer<ExtraOptions: {} = {}> = {
|
||||||
|
transform: Transform<ExtraOptions>,
|
||||||
getCacheKey: () => string,
|
getCacheKey: () => string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2016-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';
|
||||||
|
|
||||||
|
const template = require('babel-template');
|
||||||
|
|
||||||
|
const makeAsyncRequire = template('require.async(ARGS)');
|
||||||
|
|
||||||
|
const plugin = {
|
||||||
|
inherits: require('babel-plugin-syntax-dynamic-import'),
|
||||||
|
visitor: {
|
||||||
|
CallExpression(path) {
|
||||||
|
if (path.node.callee.type !== 'Import') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newImport = makeAsyncRequire({ARGS: path.node.arguments});
|
||||||
|
path.replaceWith(newImport);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = plugin;
|
Loading…
Reference in New Issue