Last active
August 21, 2018 02:02
-
-
Save njleonzhang/4626fbfa493f5a8160901755285e31e3 to your computer and use it in GitHub Desktop.
Vue jsx transform sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Babel = require('babel-core') | |
const vueJsx = require('babel-plugin-transform-vue-jsx') | |
let code = ` | |
function render() { | |
return ( | |
<div> | |
<div leon={a} onClick={this.click()} | |
{...{ | |
props: { | |
prop1: 1, | |
prop2: 2 | |
}, | |
on: { | |
event: this.handleEvent() | |
} | |
}} | |
> | |
</div> | |
</div> | |
) | |
}` | |
let result = Babel.transform(code, { | |
plugins: [ | |
vueJsx, | |
] | |
}) | |
console.log(result.code) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"devDependencies": { | |
"babel-core": "^6.26.3", | |
"babel-helper-vue-jsx-merge-props": "^2.0.3", | |
"babel-plugin-syntax-jsx": "^6.18.0", | |
"babel-plugin-transform-vue-jsx": "^3.7.0", | |
"babel-preset-env": "^1.7.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node index.js , then we get: | |
import _mergeJSXProps from "babel-helper-vue-jsx-merge-props"; | |
function render() { | |
return h("div", [h("div", _mergeJSXProps([{ | |
attrs: { leon: a }, | |
on: { | |
"click": this.click() | |
} | |
}, { | |
props, | |
on: { | |
event: this.handleEvent() | |
} | |
}]))]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment