This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) egoist <0x142857@gmail.com> (https://egoistian.com)
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.
+111
View File
@@ -0,0 +1,111 @@
# vue-no-ssr
[![NPM version](https://img.shields.io/npm/v/vue-no-ssr.svg?style=flat)](https://npmjs.com/package/vue-no-ssr) [![NPM downloads](https://img.shields.io/npm/dm/vue-no-ssr.svg?style=flat)](https://npmjs.com/package/vue-no-ssr) [![CircleCI](https://circleci.com/gh/egoist/vue-no-ssr/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/vue-no-ssr/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate)
## Install
```bash
yarn add vue-no-ssr
```
## Usage
```vue
<template>
<div id="app">
<h1>My Website</h1>
<no-ssr>
<!-- this component will only be rendered on client-side -->
<comments />
</no-ssr>
</div>
</template>
<script>
import NoSSR from 'vue-no-ssr'
export default {
components: {
'no-ssr': NoSSR
}
}
</script>
```
### Placeholder
Use a slot or text as placeholder until `<no-ssr />` is mounted on client-side.
eg, show a loading indicator.
```vue
<template>
<div id="app">
<h1>My Website</h1>
<!-- use slot -->
<no-ssr>
<comments />
     <comments-placeholder slot="placeholder" />
   </no-ssr>
<!-- or use text -->
<no-ssr placeholder="Loading...">
<comments />
</no-ssr>
</div>
</template>
<script>
import NoSSR from 'vue-no-ssr'
export default {
components: {
'no-ssr': NoSSR
}
}
</script>
```
By default the placeholder will be wrapped in a `div` tag, however you can use `placeholderTag` prop to customize it:
```vue
<no-ssr placeholder="loading" placeholader-tag="span">
<comments />
</no-ssr>
```
And you get:
```html
<span class="no-ssr-placeholder">
loading
</span>
```
If prop `placeholder` is an empty string (or `null`) and no `placeholder`
slot is found, then `<no-ssr>` will render the Vue placeholder element `<!---->`
instead of rendering the `placholder-tag` during SSR render.
## Development
```bash
yarn install
# Run example
yarn example
```
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## Author
**vue-no-ssr** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/vue-no-ssr/contributors)).
> [egoist.moe](https://egoist.moe) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)
+51
View File
@@ -0,0 +1,51 @@
/*!
* vue-no-ssr v1.1.1
* (c) 2018-present egoist <0x142857@gmail.com>
* Released under the MIT License.
*/
'use strict';
var index = {
name: 'NoSsr',
functional: true,
props: {
placeholder: String,
placeholderTag: {
type: String,
default: 'div'
}
},
render: function render(h, ref) {
var parent = ref.parent;
var slots = ref.slots;
var props = ref.props;
var ref$1 = slots();
var defaultSlot = ref$1.default; if ( defaultSlot === void 0 ) defaultSlot = [];
var placeholderSlot = ref$1.placeholder;
if (parent._isMounted) {
return defaultSlot
}
parent.$once('hook:mounted', function () {
parent.$forceUpdate();
});
if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
return h(
props.placeholderTag,
{
class: ['no-ssr-placeholder']
},
props.placeholder || placeholderSlot
)
}
// Return a placeholder element for each child in the default slot
// Or if no children return a single placeholder
return defaultSlot.length > 0 ? defaultSlot.map(function () { return h(false); }) : h(false)
}
};
module.exports = index;
+57
View File
@@ -0,0 +1,57 @@
/*!
* vue-no-ssr v1.1.1
* (c) 2018-present egoist <0x142857@gmail.com>
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.NoSSR = factory());
}(this, (function () { 'use strict';
var index = {
name: 'NoSsr',
functional: true,
props: {
placeholder: String,
placeholderTag: {
type: String,
default: 'div'
}
},
render: function render(h, ref) {
var parent = ref.parent;
var slots = ref.slots;
var props = ref.props;
var ref$1 = slots();
var defaultSlot = ref$1.default; if ( defaultSlot === void 0 ) defaultSlot = [];
var placeholderSlot = ref$1.placeholder;
if (parent._isMounted) {
return defaultSlot
}
parent.$once('hook:mounted', function () {
parent.$forceUpdate();
});
if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
return h(
props.placeholderTag,
{
class: ['no-ssr-placeholder']
},
props.placeholder || placeholderSlot
)
}
// Return a placeholder element for each child in the default slot
// Or if no children return a single placeholder
return defaultSlot.length > 0 ? defaultSlot.map(function () { return h(false); }) : h(false)
}
};
return index;
})));
+7
View File
@@ -0,0 +1,7 @@
/*!
* vue-no-ssr v1.1.1
* (c) 2018-present egoist <0x142857@gmail.com>
* Released under the MIT License.
*/
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):e.NoSSR=o()}(this,function(){"use strict";return{name:"NoSsr",functional:!0,props:{placeholder:String,placeholderTag:{type:String,default:"div"}},render:function(e,o){var n=o.parent,t=o.slots,r=o.props,d=t(),l=d.default;void 0===l&&(l=[]);var a=d.placeholder;return n._isMounted?l:(n.$once("hook:mounted",function(){n.$forceUpdate()}),r.placeholderTag&&(r.placeholder||a)?e(r.placeholderTag,{class:["no-ssr-placeholder"]},r.placeholder||a):l.length>0?l.map(function(){return e(!1)}):e(!1))}}});
//# sourceMappingURL=vue-no-ssr.min.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":null,"sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
+77
View File
@@ -0,0 +1,77 @@
{
"_args": [
[
"vue-no-ssr@1.1.1",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "vue-no-ssr@1.1.1",
"_id": "vue-no-ssr@1.1.1",
"_inBundle": false,
"_integrity": "sha512-ZMjqRpWabMPqPc7gIrG0Nw6vRf1+itwf0Itft7LbMXs2g3Zs/NFmevjZGN1x7K3Q95GmIjWbQZTVerxiBxI+0g==",
"_location": "/vue-no-ssr",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "vue-no-ssr@1.1.1",
"name": "vue-no-ssr",
"escapedName": "vue-no-ssr",
"rawSpec": "1.1.1",
"saveSpec": null,
"fetchSpec": "1.1.1"
},
"_requiredBy": [
"/@nuxt/vue-app"
],
"_resolved": "https://registry.npmjs.org/vue-no-ssr/-/vue-no-ssr-1.1.1.tgz",
"_spec": "1.1.1",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"author": {
"name": "egoist",
"email": "0x142857@gmail.com"
},
"bugs": {
"url": "https://github.com/egoist/vue-no-ssr/issues"
},
"dependencies": {},
"description": "Vue component to wrap non SSR friendly components",
"devDependencies": {
"bili": "^0.16.0-rc.1",
"eslint-config-rem": "^3.0.0",
"poi": "^9.3.1",
"xo": "^0.18.0"
},
"files": [
"dist"
],
"homepage": "https://github.com/egoist/vue-no-ssr#readme",
"license": "MIT",
"main": "dist/vue-no-ssr.common.js",
"name": "vue-no-ssr",
"poi": {
"entry": "example/index.js",
"dist": "example/dist"
},
"repository": {
"url": "git+https://github.com/egoist/vue-no-ssr.git",
"type": "git"
},
"scripts": {
"build": "npm run build:cjs && npm run build:umd",
"build:cjs": "FORMAT=cjs bili",
"build:umd": "FORMAT=umd bili",
"example": "poi",
"lint": "xo",
"prepublish": "npm run build",
"test": "echo 'no tests!' && npm run lint"
},
"unpkg": "dist/vue-no-ssr.min.js",
"version": "1.1.1",
"xo": {
"extends": "rem/prettier",
"ignores": [
"example/**"
]
}
}