build: rename vue-compat
This commit is contained in:
3
packages/vue-compat/.npmignore
Normal file
3
packages/vue-compat/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
__tests__/
|
||||
__mocks__/
|
||||
dist/packages
|
||||
3
packages/vue-compat/README.md
Normal file
3
packages/vue-compat/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# vue-compat
|
||||
|
||||
The 2.x compatibility build.
|
||||
32
packages/vue-compat/__tests__/compat.spec.ts
Normal file
32
packages/vue-compat/__tests__/compat.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
;(global as any).__COMPAT__ = true
|
||||
|
||||
import Vue from '../src/index'
|
||||
|
||||
describe('2.x compat build', async () => {
|
||||
test('should work', async () => {
|
||||
const root = document.createElement('div')
|
||||
document.body.appendChild(root)
|
||||
|
||||
const instance = new Vue({
|
||||
data() {
|
||||
return { count: 0 }
|
||||
},
|
||||
methods: {
|
||||
change() {
|
||||
this.count++
|
||||
}
|
||||
},
|
||||
render(h: any) {
|
||||
return h('div', this.count)
|
||||
}
|
||||
}).$mount(root)
|
||||
|
||||
expect(instance.count).toBe(0)
|
||||
expect(root.textContent).toBe('0')
|
||||
|
||||
instance.change()
|
||||
expect(instance.count).toBe(1)
|
||||
await Vue.nextTick()
|
||||
expect(root.textContent).toBe('1')
|
||||
})
|
||||
})
|
||||
7
packages/vue-compat/index.js
Normal file
7
packages/vue-compat/index.js
Normal file
@@ -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')
|
||||
}
|
||||
30
packages/vue-compat/package.json
Normal file
30
packages/vue-compat/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "vue-compat",
|
||||
"version": "3.0.0-alpha.1",
|
||||
"description": "vue",
|
||||
"main": "index.js",
|
||||
"module": "dist/vue.esm-bundler.js",
|
||||
"unpkg": "dist/vue.global.js",
|
||||
"sideEffects": false,
|
||||
"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"
|
||||
}
|
||||
}
|
||||
41
packages/vue-compat/src/index.ts
Normal file
41
packages/vue-compat/src/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
h,
|
||||
render,
|
||||
nextTick,
|
||||
createComponentInstance,
|
||||
createComponentClassFromOptions
|
||||
} from '@vue/renderer-dom'
|
||||
|
||||
// Note: typing for this is intentionally loose, as it will be using 2.x types.
|
||||
|
||||
class Vue {
|
||||
static h: any = h
|
||||
static render: any = render
|
||||
static nextTick: any = nextTick
|
||||
|
||||
constructor(options: any) {
|
||||
// convert it to a class
|
||||
const Component = createComponentClassFromOptions(options || {})
|
||||
const vnode = h(Component)
|
||||
const instance = createComponentInstance(vnode)
|
||||
|
||||
function mount(el: any) {
|
||||
const dom = typeof el === 'string' ? document.querySelector(el) : el
|
||||
render(vnode, dom)
|
||||
return instance.$proxy
|
||||
}
|
||||
|
||||
if (options.el) {
|
||||
return mount(options.el)
|
||||
} else {
|
||||
;(instance as any).$mount = mount
|
||||
return instance.$proxy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Vue {
|
||||
$mount(el: any): any
|
||||
}
|
||||
|
||||
export default Vue
|
||||
Reference in New Issue
Block a user