-
Notifications
You must be signed in to change notification settings - Fork 98
feat: add @vue/composition-api support #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
356870a
feat: add babel-sugar-composition-api-inject-h
antfu eda1741
feat: add @vue/babel-sugar-composition-api-render-instance
antfu c172788
fix: plugin order
antfu 715dfc0
Update packages/babel-sugar-composition-api-render-instance/README.md
antfu 243bac4
chore: codereview update
antfu fd21936
chore: update readme
antfu 3aca691
chore: fix hightlight
antfu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
## @vue/babel-sugar-composition-api-inject-h | ||
|
||
> Ported from [luwanquan/babel-preset-vca-jsx](https://github.com/luwanquan/babel-preset-vca-jsx) by [@luwanquan](https://github.com/luwanquan) | ||
|
||
Syntactic sugar for automatic `h` inject in JSX with @vue/composition-api. | ||
|
||
### Babel Compatibility Notes | ||
|
||
- This repo is only compatible with Babel 7.x | ||
|
||
### Usage | ||
|
||
Install the dependencies: | ||
|
||
```sh | ||
# for yarn: | ||
yarn add @vue/babel-sugar-composition-api-inject-h | ||
# for npm: | ||
npm install @vue/babel-sugar-composition-api-inject-h --save | ||
``` | ||
|
||
In your `.babelrc`: | ||
|
||
```json | ||
{ | ||
"plugins": ["@vue/babel-sugar-composition-api-inject-h"] | ||
} | ||
``` | ||
|
||
However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead. | ||
|
||
### Details | ||
|
||
This plugin automatically injects `h` in every method that has JSX. By using this plugin you don't have to always specifically declare `h` as first parameter in your `render()` function. | ||
|
||
```js | ||
// Without @vue/babel-sugar-inject-h | ||
import { h } from '@vue/composition-api' | ||
|
||
export default { | ||
setup() { | ||
return () => <button /> | ||
}, | ||
} | ||
|
||
// With @vue/babel-sugar-inject-h | ||
export default { | ||
setup() { | ||
return () => <button /> | ||
}, | ||
} | ||
``` |
42 changes: 42 additions & 0 deletions
42
packages/babel-sugar-composition-api-inject-h/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@vue/babel-sugar-composition-api-inject-h", | ||
"version": "1.1.2", | ||
"description": "Babel syntactic sugar for h automatic injection for Vue JSX with @vue/composition-api", | ||
"main": "dist/plugin.js", | ||
"repository": "https://github.com/vuejs/jsx/tree/master/packages/babel-sugar-composition-api-inject-h", | ||
"author": "luwanquan <luwanquan@f-road.com.cn>", | ||
"license": "MIT", | ||
"private": false, | ||
"files": [], | ||
"scripts": { | ||
"prepublish": "yarn build", | ||
"build": "rollup -c", | ||
"build:test": "rollup -c rollup.config.testing.js", | ||
"pretest": "yarn build:test", | ||
"test": "nyc --reporter=html --reporter=text-summary ava -v test/test.js" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.0", | ||
"@babel/core": "^7.2.0", | ||
"@babel/preset-env": "^7.2.0", | ||
"ava": "^0.25.0", | ||
"nyc": "^13.1.0", | ||
"rollup": "^0.67.4", | ||
"rollup-plugin-babel": "4.0.3", | ||
"rollup-plugin-istanbul": "^2.0.1", | ||
"rollup-plugin-uglify-es": "^0.0.1", | ||
"vue": "^2.5.17" | ||
}, | ||
"dependencies": { | ||
"@babel/plugin-syntax-jsx": "^7.2.0" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-0" | ||
}, | ||
"nyc": { | ||
"exclude": [ | ||
"dist", | ||
"test" | ||
] | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/babel-sugar-composition-api-inject-h/rollup.config.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { rollup } from 'rollup' | ||
import babel from 'rollup-plugin-babel' | ||
import uglify from 'rollup-plugin-uglify-es' | ||
|
||
export default { | ||
input: 'src/index.js', | ||
plugins: [ | ||
babel({ | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: '8', | ||
}, | ||
modules: false, | ||
loose: true, | ||
}, | ||
], | ||
], | ||
}), | ||
uglify(), | ||
], | ||
output: [ | ||
{ | ||
file: 'dist/plugin.js', | ||
format: 'cjs', | ||
}, | ||
], | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/babel-sugar-composition-api-inject-h/rollup.config.testing.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import istanbul from 'rollup-plugin-istanbul' | ||
|
||
export default { | ||
input: 'src/index.js', | ||
plugins: [istanbul()], | ||
output: [ | ||
{ | ||
file: 'dist/plugin.testing.js', | ||
format: 'cjs', | ||
}, | ||
], | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.