Skip to content

docs: guide users to use versioned CDN #397

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 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ npm install @vue/composition-api
yarn add @vue/composition-api
```

You must install `@vue/composition-api` via `Vue.use()` before you can use the [Composition API](https://composition-api.vuejs.org/) to compose your component.
You must install `@vue/composition-api` as a plugin via `Vue.use()` before you can use the [Composition API](https://composition-api.vuejs.org/) to compose your component.

```js
import Vue from 'vue'
Expand All @@ -27,17 +27,24 @@ Vue.use(VueCompositionApi)
```

```js
// in components
// use the APIs
import { ref, reactive } from '@vue/composition-api'
```

> :bulb: When you migrate to Vue 3, just replacing `@vue/composition-api` to `vue` and your code should just work.

### CDN

Add the following lines in your `<head>` to import Vue and `@vue/composition-api`.

<!--cdn-links-start-->
```html
<script src="https://unpkg.com/@vue/composition-api/dist/vue-composition-api.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/@vue/[email protected]"></script>
```
<!--cdn-links-end-->

The package will be exposed to global variable `window.vueCompositionApi`
`@vue/composition-api` will be exposed to global variable `window.vueCompositionApi` and you have to install it before using the APIs.

```js
// install the plugin
Expand Down
14 changes: 4 additions & 10 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ Vue 2 插件用于提供 Vue 3 中的 **组合式 API**.

---

# 导航

- [安装](#安装)
- [使用](#使用)
- [TypeScript](#TypeScript)
- [TSX](#tsx)
- [限制](#限制)
- [更新日志](https://github.com/vuejs/composition-api/blob/master/CHANGELOG.md)

# 安装

**npm**
Expand All @@ -36,9 +27,12 @@ yarn add @vue/composition-api

**CDN**

<!--cdn-links-start-->
```html
<script src="https://unpkg.com/@vue/composition-api/dist/vue-composition-api.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/@vue/[email protected]"></script>
```
<!--cdn-links-end-->

通过全局变量 `window.vueCompositionApi` 来使用。

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"main": "dist/vue-composition-api.js",
"umd:main": "dist/vue-composition-api.umd.js",
"browser": "dist/vue-composition-api.umd.js",
"module": "dist/vue-composition-api.module.js",
"typings": "dist/index.d.ts",
"author": {
Expand All @@ -31,10 +32,11 @@
"test": "yarn test-dts && yarn test-unit",
"test-unit": "cross-env NODE_ENV=test jest",
"test-dts": "tsc -p ./test-dts/tsconfig.json && yarn build && tsc -p ./test-dts/tsconfig.build.json",
"update-readme": "node ./scripts/update-readme.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"prepublish": "yarn test",
"postpublish": "yarn release-gh",
"version": "yarn changelog && git add CHANGELOG.md",
"version": "yarn changelog && yarn update-readme && git add CHANGELOG.md README.*",
"release": "yarn version && git push --follow-tags && yarn publish --non-interactive",
"release-gh": "conventional-github-releaser -p angular"
},
Expand Down
29 changes: 29 additions & 0 deletions scripts/update-readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { promises: fs } = require('fs')
const path = require('path')
const { version } = require('../package.json')

const files = ['../README.md', '../README.zh-CN.md']

const MakeLinks = (version, vueVersion = '2.6') =>
`
\`\`\`html
<script src="https://cdn.jsdelivr.net/npm/vue@${vueVersion}"></script>
<script src="https://cdn.jsdelivr.net/npm/@vue/composition-api@${version}"></script>
\`\`\`
`

;(async () => {
const links = MakeLinks(version)

for (const file of files) {
const filepath = path.resolve(__dirname, file)
const raw = await fs.readFile(filepath, 'utf-8')

const updated = raw.replace(
/<!--cdn-links-start-->([\s\S]*)<!--cdn-links-end-->/g,
`<!--cdn-links-start-->${links}<!--cdn-links-end-->`
)

await fs.writeFile(filepath, updated, 'utf-8')
}
})()