mirror of https://github.com/status-im/metro.git
Update Readme + change default transform
Reviewed By: cpojer Differential Revision: D6401596 fbshipit-source-id: 8928abb825933edd84c508a4f04f50c748725722
This commit is contained in:
parent
7b5ae96479
commit
70dadc63f9
14
README.md
14
README.md
|
@ -137,14 +137,16 @@ The JavaScript transformer (`transformModulePath`) is the place where JS code wi
|
|||
|
||||
## Method `transform(module)`
|
||||
|
||||
Mandatory method that will transform code. The object received has information about the module being transformed (e.g its path, code...) and the returned object has to contain a `code` key that is the result of the transform. The default transformer shipped is a pretty good place to start:
|
||||
Mandatory method that will transform code. The object received has information about the module being transformed (e.g its path, code...) and the returned object has to contain an `ast` key that is the AST representation of the transformed code. The default shipped transformer does the bare minimum amount of work by just parsing the code to AST:
|
||||
|
||||
```js
|
||||
module.exports.transform = file => {
|
||||
return {
|
||||
code: file.src,
|
||||
};
|
||||
});
|
||||
const babylon = require('babylon');
|
||||
|
||||
module.exports.transform = (file: {filename: string, src: string}) => {
|
||||
const ast = babylon.parse(code, {sourceType: 'module'});
|
||||
|
||||
return {ast};
|
||||
};
|
||||
```
|
||||
|
||||
If you would like to plug-in babel, you can simply do that by passing the code to it:
|
||||
|
|
|
@ -11,4 +11,10 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
module.exports.transform = (file: {src: string}) => ({code: file.src});
|
||||
const babylon = require('babylon');
|
||||
|
||||
module.exports.transform = (file: {filename: string, src: string}) => {
|
||||
const ast = babylon.parse(file.src, {sourceType: 'module'});
|
||||
|
||||
return {ast};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue