diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bfe2f6e --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: dist + +dist: + webpack --config build/webpack.build.config.js diff --git a/build/webpack.build.config.js b/build/webpack.build.config.js new file mode 100644 index 0000000..58b3e17 --- /dev/null +++ b/build/webpack.build.config.js @@ -0,0 +1,39 @@ +var webpack = require("webpack"); +var version = require("../package.json").version; +var banner = + "/**\n" + + " * vue-async-data v" + version + "\n" + + " * https://github.com/vuejs/vue-async-data\n" + + " * Released under the MIT License.\n" + + " */\n"; + +module.exports = [ + + { + entry: "./src/vue-async-data", + output: { + path: "./dist", + filename: "vue-async-data.js", + library: "VueAsyncData", + libraryTarget: "umd" + }, + plugins: [ + new webpack.BannerPlugin(banner, {raw: true}) + ] + }, + + { + entry: "./src/vue-async-data", + output: { + path: "./dist", + filename: "vue-async-data.min.js", + library: "VueAsyncData", + libraryTarget: "umd" + }, + plugins: [ + new webpack.optimize.UglifyJsPlugin, + new webpack.BannerPlugin(banner, {raw: true}) + ] + } + +]; diff --git a/dist/vue-async-data.js b/dist/vue-async-data.js new file mode 100644 index 0000000..8997580 --- /dev/null +++ b/dist/vue-async-data.js @@ -0,0 +1,139 @@ +/** + * vue-async-data v1.0.2 + * https://github.com/vuejs/vue-async-data + * Released under the MIT License. + */ + +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["VueAsyncData"] = factory(); + else + root["VueAsyncData"] = factory(); +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + (function () { + var vue // lazy bind + + var asyncData = { + created: function () { + if (!vue) { + console.warn('[vue-async-data] not installed!') + return + } + if (this.$options.asyncData) { + if (this._defineMeta) { + // 0.12 compat + this._defineMeta('$loadingAsyncData', true) + } else { + // ^1.0.0-alpha + vue.util.defineReactive(this, '$loadingAsyncData', true) + } + } + }, + compiled: function () { + this.reloadAsyncData() + }, + methods: { + reloadAsyncData: function () { + var load = this.$options.asyncData + if (load) { + var self = this + var resolve = function (data) { + if (data) { + for (var key in data) { + self.$set(key, data[key]) + } + } + self.$loadingAsyncData = false + self.$emit('async-data') + } + var reject = function (reason) { + var msg = '[vue] async data load failed' + if (reason instanceof Error) { + console.warn(msg) + throw reason + } else { + console.warn(msg + ': ' + reason) + } + } + this.$loadingAsyncData = true + var res = load.call(this, resolve, reject) + if (res && typeof res.then === 'function') { + res.then(resolve, reject) + } + } + } + } + } + + var api = { + mixin: asyncData, + install: function (Vue, options) { + vue = Vue + Vue.options = Vue.util.mergeOptions(Vue.options, asyncData) + } + } + + if(true) { + module.exports = api + } else if(typeof define === 'function' && define.amd) { + define(function () { return api }) + } else if (typeof window !== 'undefined') { + window.VueAsyncData = api + } + })() + + +/***/ } +/******/ ]) +}); +; \ No newline at end of file diff --git a/dist/vue-async-data.min.js b/dist/vue-async-data.min.js new file mode 100644 index 0000000..15e1774 --- /dev/null +++ b/dist/vue-async-data.min.js @@ -0,0 +1,7 @@ +/** + * vue-async-data v1.0.2 + * https://github.com/vuejs/vue-async-data + * Released under the MIT License. + */ + +!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.VueAsyncData=n():t.VueAsyncData=n()}(this,function(){return function(t){function n(e){if(o[e])return o[e].exports;var a=o[e]={exports:{},id:e,loaded:!1};return t[e].call(a.exports,a,a.exports,n),a.loaded=!0,a.exports}var o={};return n.m=t,n.c=o,n.p="",n(0)}([function(t,n,o){!function(){var n,o={created:function(){return n?void(this.$options.asyncData&&(this._defineMeta?this._defineMeta("$loadingAsyncData",!0):n.util.defineReactive(this,"$loadingAsyncData",!0))):void console.warn("[vue-async-data] not installed!")},compiled:function(){this.reloadAsyncData()},methods:{reloadAsyncData:function(){var t=this.$options.asyncData;if(t){var n=this,o=function(t){if(t)for(var o in t)n.$set(o,t[o]);n.$loadingAsyncData=!1,n.$emit("async-data")},e=function(t){var n="[vue] async data load failed";if(t instanceof Error)throw console.warn(n),t;console.warn(n+": "+t)};this.$loadingAsyncData=!0;var a=t.call(this,o,e);a&&"function"==typeof a.then&&a.then(o,e)}}}},e={mixin:o,install:function(t,e){n=t,t.options=t.util.mergeOptions(t.options,o)}};t.exports=e}()}])}); \ No newline at end of file diff --git a/vue-async-data.js b/src/vue-async-data.js similarity index 100% rename from vue-async-data.js rename to src/vue-async-data.js