From 360ab65117c0b8c0ba3b1038ae2e18b56ddf651a Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 19 Sep 2018 21:52:24 -0400 Subject: [PATCH] build: add vue 2.x compat package --- packages/vue/.npmignore | 3 +++ packages/vue/README.md | 3 +++ packages/vue/index.js | 7 +++++++ packages/vue/package.json | 30 ++++++++++++++++++++++++++++++ packages/vue/src/index.ts | 27 +++++++++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 packages/vue/.npmignore create mode 100644 packages/vue/README.md create mode 100644 packages/vue/index.js create mode 100644 packages/vue/package.json create mode 100644 packages/vue/src/index.ts diff --git a/packages/vue/.npmignore b/packages/vue/.npmignore new file mode 100644 index 00000000..bb5c8a54 --- /dev/null +++ b/packages/vue/.npmignore @@ -0,0 +1,3 @@ +__tests__/ +__mocks__/ +dist/packages \ No newline at end of file diff --git a/packages/vue/README.md b/packages/vue/README.md new file mode 100644 index 00000000..90a7fe2a --- /dev/null +++ b/packages/vue/README.md @@ -0,0 +1,3 @@ +# vue + +The 2.x compatibility build. diff --git a/packages/vue/index.js b/packages/vue/index.js new file mode 100644 index 00000000..7a3dc2d8 --- /dev/null +++ b/packages/vue/index.js @@ -0,0 +1,7 @@ +'use strict' + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./dist/vue.cjs.prod.js') +} else { + module.exports = require('./dist/vue.cjs.js') +} diff --git a/packages/vue/package.json b/packages/vue/package.json new file mode 100644 index 00000000..10cce245 --- /dev/null +++ b/packages/vue/package.json @@ -0,0 +1,30 @@ +{ + "name": "vue", + "version": "3.0.0-alpha.1", + "description": "vue", + "main": "index.js", + "module": "dist/vue.esm-bundler.js", + "typings": "dist/index.d.ts", + "unpkg": "dist/vue.global.js", + "buildOptions": { + "name": "Vue", + "compat": true, + "formats": ["esm", "cjs", "global", "esm-browser"] + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuejs/vue.git" + }, + "keywords": [ + "vue" + ], + "author": "Evan You", + "license": "MIT", + "bugs": { + "url": "https://github.com/vuejs/vue/issues" + }, + "homepage": "https://github.com/vuejs/vue/tree/dev/packages/vue#readme", + "dependencies": { + "@vue/renderer-dom": "3.0.0-alpha.1" + } +} diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts new file mode 100644 index 00000000..d98bad21 --- /dev/null +++ b/packages/vue/src/index.ts @@ -0,0 +1,27 @@ +import { h, render, ComponentOptions } from '@vue/renderer-dom' + +function Vue(options: ComponentOptions & { el: any }) { + const { el, render: r } = options + + if (r) { + options.render = function(props, slots) { + return r.call(this, h, props, slots) + } + } + + function mount(el: any) { + const dom = document.querySelector(el) + render(h(options), dom) + return (dom as any).vnode.children.$proxy + } + + if (el) { + return mount(el) + } else { + return { + $mount: mount + } + } +} + +export default Vue