This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015-2016 Evan You
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+60
View File
@@ -0,0 +1,60 @@
# vue-hot-reload-api
> Note: `vue-hot-reload-api@2.x` only works with `vue@2.x`
Hot reload API for Vue components. This is what [vue-loader](https://github.com/vuejs/vue-loader) and [vueify](https://github.com/vuejs/vueify) use under the hood.
## Usage
You will only be using this if you are writing some build toolchain based on Vue components. For normal application usage, just use `vue-loader` or `vueify`.
``` js
// define a component as an options object
const myComponentOptions = {
data () { ... },
created () { ... },
render () { ... }
}
// assuming Webpack's HMR API.
// https://webpack.github.io/docs/hot-module-replacement.html
if (module.hot) {
const api = require('vue-hot-reload-api')
const Vue = require('vue')
// make the API aware of the Vue that you are using.
// also checks compatibility.
api.install(Vue)
// compatibility can be checked via api.compatible after installation
if (!api.compatible) {
throw new Error('vue-hot-reload-api is not compatible with the version of Vue you are using.')
}
// indicate this module can be hot-reloaded
module.hot.accept()
if (!module.hot.data) {
// for each component option object to be hot-reloaded,
// you need to create a record for it with a unique id.
// do this once on startup.
api.createRecord('very-unique-id', myComponentOptions)
} else {
// if a component has only its template or render function changed,
// you can force a re-render for all its active instances without
// destroying/re-creating them. This keeps all current app state intact.
api.rerender('very-unique-id', myComponentOptions)
// --- OR ---
// if a component has non-template/render options changed,
// it needs to be fully reloaded. This will destroy and re-create all its
// active instances (and their children).
api.reload('very-unique-id', myComponentOptions)
}
}
```
## License
[MIT](http://opensource.org/licenses/MIT)
+59
View File
@@ -0,0 +1,59 @@
# vue-hot-reload-api
> 注意: `vue-hot-reload-api@2.x` 仅支持 `vue@2.x`
Vue components 热加载API。[vue-loader](https://github.com/vuejs/vue-loader) 和 [vueify](https://github.com/vuejs/vueify) 底层使用的就是这个。
## 用法
你仅会在开发一个基于 Vue components 构建工具的时候用到这个。对于普通的应用,使用 `vue-loader` 或者 `vueify` 就可以了。
``` js
// 定义一个组件作为选项对象
const myComponentOptions = {
data () { ... },
created () { ... },
render () { ... }
}
// 检测 Webpack 的 HMR API
// https://webpack.github.io/docs/hot-module-replacement.html
if (module.hot) {
const api = require('vue-hot-reload-api')
const Vue = require('vue')
// 将 API 安装到 Vue,并且检查版本的兼容性
api.install(Vue)
// 在安装之后使用 api.compatible 来检查兼容性
if (!api.compatible) {
throw new Error('vue-hot-reload-api与当前Vue的版本不兼容')
}
// 此模块接受热重载
module.hot.accept()
if (!module.hot.data) {
// 为了将每一个组件中的选项变得可以热加载,
// 你需要用一个不重复的id创建一次记录,
// 只需要在启动的时候做一次。
api.createRecord('very-unique-id', myComponentOptions)
} else {
// 如果一个组件只是修改了模板或是 render 函数,
// 只要把所有相关的实例重新渲染一遍就可以了,而不需要销毁重建他们。
// 这样就可以完整的保持应用的当前状态。
api.rerender('very-unique-id', myComponentOptions)
// --- 或者 ---
// 如果一个组件更改了除 template 或 render 之外的选项,
// 就需要整个重新加载。
// 这将销毁并重建整个组件(包括子组件)。
api.reload('very-unique-id', myComponentOptions)
}
}
```
## License
[MIT](http://opensource.org/licenses/MIT)
+144
View File
@@ -0,0 +1,144 @@
var Vue // late bind
var version
var map = window.__VUE_HOT_MAP__ = Object.create(null)
var installed = false
var isBrowserify = false
var initHookName = 'beforeCreate'
exports.install = function (vue, browserify) {
if (installed) return
installed = true
Vue = vue.__esModule ? vue.default : vue
version = Vue.version.split('.').map(Number)
isBrowserify = browserify
// compat with < 2.0.0-alpha.7
if (Vue.config._lifecycleHooks.indexOf('init') > -1) {
initHookName = 'init'
}
exports.compatible = version[0] >= 2
if (!exports.compatible) {
console.warn(
'[HMR] You are using a version of vue-hot-reload-api that is ' +
'only compatible with Vue.js core ^2.0.0.'
)
return
}
}
/**
* Create a record for a hot module, which keeps track of its constructor
* and instances
*
* @param {String} id
* @param {Object} options
*/
exports.createRecord = function (id, options) {
var Ctor = null
if (typeof options === 'function') {
Ctor = options
options = Ctor.options
}
makeOptionsHot(id, options)
map[id] = {
Ctor: Vue.extend(options),
instances: []
}
}
/**
* Make a Component options object hot.
*
* @param {String} id
* @param {Object} options
*/
function makeOptionsHot (id, options) {
injectHook(options, initHookName, function () {
map[id].instances.push(this)
})
injectHook(options, 'beforeDestroy', function () {
var instances = map[id].instances
instances.splice(instances.indexOf(this), 1)
})
}
/**
* Inject a hook to a hot reloadable component so that
* we can keep track of it.
*
* @param {Object} options
* @param {String} name
* @param {Function} hook
*/
function injectHook (options, name, hook) {
var existing = options[name]
options[name] = existing
? Array.isArray(existing)
? existing.concat(hook)
: [existing, hook]
: [hook]
}
function tryWrap (fn) {
return function (id, arg) {
try { fn(id, arg) } catch (e) {
console.error(e)
console.warn('Something went wrong during Vue component hot-reload. Full reload required.')
}
}
}
exports.rerender = tryWrap(function (id, options) {
var record = map[id]
if (!options) {
record.instances.slice().forEach(function (instance) {
instance.$forceUpdate()
})
return
}
if (typeof options === 'function') {
options = options.options
}
record.Ctor.options.render = options.render
record.Ctor.options.staticRenderFns = options.staticRenderFns
record.instances.slice().forEach(function (instance) {
instance.$options.render = options.render
instance.$options.staticRenderFns = options.staticRenderFns
instance._staticTrees = [] // reset static trees
instance.$forceUpdate()
})
})
exports.reload = tryWrap(function (id, options) {
var record = map[id]
if (options) {
if (typeof options === 'function') {
options = options.options
}
makeOptionsHot(id, options)
if (version[1] < 2) {
// preserve pre 2.2 behavior for global mixin handling
record.Ctor.extendOptions = options
}
var newCtor = record.Ctor.super.extend(options)
record.Ctor.options = newCtor.options
record.Ctor.cid = newCtor.cid
record.Ctor.prototype = newCtor.prototype
if (newCtor.release) {
// temporary global mixin strategy used in < 2.0.0-alpha.6
newCtor.release()
}
}
record.instances.slice().forEach(function (instance) {
if (instance.$vnode && instance.$vnode.context) {
instance.$vnode.context.$forceUpdate()
} else {
console.warn('Root or manually mounted instance modified. Full reload required.')
}
})
})
+88
View File
@@ -0,0 +1,88 @@
{
"_args": [
[
{
"raw": "vue-hot-reload-api@^2.0.11",
"scope": null,
"escapedName": "vue-hot-reload-api",
"name": "vue-hot-reload-api",
"rawSpec": "^2.0.11",
"spec": ">=2.0.11 <3.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\vue-loader"
]
],
"_from": "vue-hot-reload-api@>=2.0.11 <3.0.0",
"_id": "vue-hot-reload-api@2.1.0",
"_inCache": true,
"_location": "/vue-hot-reload-api",
"_nodeVersion": "7.8.0",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/vue-hot-reload-api-2.1.0.tgz_1492421778603_0.8060554063413292"
},
"_npmUser": {
"name": "yyx990803",
"email": "yyx990803@gmail.com"
},
"_npmVersion": "4.2.0",
"_phantomChildren": {},
"_requested": {
"raw": "vue-hot-reload-api@^2.0.11",
"scope": null,
"escapedName": "vue-hot-reload-api",
"name": "vue-hot-reload-api",
"rawSpec": "^2.0.11",
"spec": ">=2.0.11 <3.0.0",
"type": "range"
},
"_requiredBy": [
"/vue-loader"
],
"_resolved": "https://registry.npmjs.org/vue-hot-reload-api/-/vue-hot-reload-api-2.1.0.tgz",
"_shasum": "9ca58a6e0df9078554ce1708688b6578754d86de",
"_shrinkwrap": null,
"_spec": "vue-hot-reload-api@^2.0.11",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\vue-loader",
"author": {
"name": "Evan You"
},
"bugs": {
"url": "https://github.com/vuejs/vue-hot-reload-api/issues"
},
"dependencies": {},
"description": "hot reload api for *.vue components",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "9ca58a6e0df9078554ce1708688b6578754d86de",
"tarball": "https://registry.npmjs.org/vue-hot-reload-api/-/vue-hot-reload-api-2.1.0.tgz"
},
"gitHead": "03707e4b7dcd0e4d280d941db90f408b5a24379f",
"homepage": "https://github.com/vuejs/vue-hot-reload-api#readme",
"keywords": [
"vue",
"hot",
"reload"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "yyx990803",
"email": "yyx990803@gmail.com"
}
],
"name": "vue-hot-reload-api",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vue-hot-reload-api.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "2.1.0"
}