All Projects → TatsuUkraine → vue-ssr-example

TatsuUkraine / vue-ssr-example

Licence: other
Ready for use Example for Vue + Vuex + TS + SSR + Jest

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vue-ssr-example

Universal Hmr Ssr React Redux
⚡A Universal Javascript App Utilizing Express, Webpack, React, Redux and React Router with Server Side Rendering and Hot Module Reloading ⚡
Stars: ✭ 60 (+160.87%)
Mutual labels:  server-side-rendering, hot-reload
easywebpack-vue
Vue Webpack Building Solution, Support Vue Server Side Render (SSR), Client Side Render (CSR) Building
Stars: ✭ 29 (+26.09%)
Mutual labels:  server-side-rendering, hot-reload
Easywebpack
A Simple, Powerful Webpack Front-End Development Solution
Stars: ✭ 452 (+1865.22%)
Mutual labels:  server-side-rendering, hot-reload
Universal React Redux
🧐 A sensible universal starter kit for React + Redux
Stars: ✭ 112 (+386.96%)
Mutual labels:  server-side-rendering, hot-reload
V2 Universal Js Hmr Ssr React Redux
⚡ (V2) Universal JS - Server Side Rendering, Code Splitting and Hot Module Reloading ⚡
Stars: ✭ 147 (+539.13%)
Mutual labels:  server-side-rendering, hot-reload
ultimate-hot-boilerplate
🚀 node-react universal app boilerplate with everything on hot reload, SSR, GraphQL, Flow included
Stars: ✭ 35 (+52.17%)
Mutual labels:  server-side-rendering, hot-reload
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+7869.57%)
Mutual labels:  server-side-rendering, hot-reload
ves
Vue SSR(Server Side Render) Web Framework for Egg
Stars: ✭ 23 (+0%)
Mutual labels:  server-side-rendering, vue-ssr
universal-react-relay-starter-kit
A starter kit for React in combination with Relay including a GraphQL server, server side rendering, code splitting, i18n, SEO.
Stars: ✭ 14 (-39.13%)
Mutual labels:  server-side-rendering
fish
fish 是一个方便开发go程序的工具。 监视文件修改,然后编译go程序并自动运行。
Stars: ✭ 22 (-4.35%)
Mutual labels:  hot-reload
universal
A counterpart to common package to be used with Angular Universal
Stars: ✭ 115 (+400%)
Mutual labels:  server-side-rendering
md-svg-vue
Material design icons by Google for Vue.js & Nuxt.js (server side support & inline svg with path)
Stars: ✭ 14 (-39.13%)
Mutual labels:  server-side-rendering
boldr
React based CMF / blogging engine using Redux, Postgres, Node, and more...
Stars: ✭ 78 (+239.13%)
Mutual labels:  server-side-rendering
prism
(No longer in development). Experimental compiler for building isomorphic web applications with web components.
Stars: ✭ 106 (+360.87%)
Mutual labels:  server-side-rendering
sveltekit-starter
Sveltekit starter project created with sveltekit, typescript, tailwindcss, postcss, husky, and storybook. The project has the structure set up for the scaleable web application.
Stars: ✭ 482 (+1995.65%)
Mutual labels:  server-side-rendering
easywebpack-react
React Webpack Building Solution, Support React Server Side Render (SSR), Client Side Render (CSR) Building
Stars: ✭ 14 (-39.13%)
Mutual labels:  hot-reload
docsify-ssr-demo
NOTICE: This repo is outdated and SSR is work-in-progress.
Stars: ✭ 61 (+165.22%)
Mutual labels:  server-side-rendering
plug-react
React components and hooks to plug your React applications into Croct.
Stars: ✭ 76 (+230.43%)
Mutual labels:  server-side-rendering
react-ssr-error-boundary
No description or website provided.
Stars: ✭ 33 (+43.48%)
Mutual labels:  server-side-rendering
rsp
A server-state reactive Java web framework for building real-time user interfaces and UI components.
Stars: ✭ 35 (+52.17%)
Mutual labels:  server-side-rendering

Ready for use Example for Vue + Vuex + TS + SSR + Jest

Inspired by Vue SSR and Evan You example

API

This project uses JSON API playground that was made according to JSON API Spec API layer is placed in /src/api folder (according to suggestions from Vuex doc)

API layer uses Axios (implementation is in /src/service) transport to make requests over HTTP

Vuex

Store is split on modules in /src/store

SSR (Server Side Rendering)

This project is configured with Webpack + Express.

<script>
    export default {
        waitAsyncData: false, //default: true
        
        asyncData () {
            return new Promise((res, rej) => res())
        }
    }
</script>

During server rendering, App will find matching Components by requested URL that has asyncData method.

Highly resomended

Make API requests to fetch data, that will be used in child components or layouts, in asyncData - to prepare all needed data, that you are going to use. It will prevent you from problems when SSR rendered page and Client rendered page will be contains different result.

asyncData should return Promise, that should be resolved after fetched data are ready for rendering.

Server won't continue rendering until all asyncData will be resolved

For client build this method will be used on route change.

By default component won't be mounted (route won't be proceeded) until all asyncData methods from all matched components will be resolved. As a result this will prevent user from navigation, until all data will be loaded for new route

As an option it can be switched off, but only for Client app with help of waitAsyncData flag.

If waitAsyncData will be FALSE asyncData won't block app from navigation. It still will stop rendering until Promise will be resolved.

.ENV

You can modify environment variables, that will be exported in process.env.

Default file .env should be placed in root folder. If needed path can be changed in /build/env-loader.js

Variables in default file can be changed with .env.{environent}, where environment defines based on NODE_ENV. For example, if NODE_ENV='development' builder will try to load .env.development after .env file

Properties VUE_ENV and NODE_ENV in .env files will be ignored

Also you can create files with .local postfix (.env.local, .env.{environent}.local). Such files will be loaded last. They are added to GitIgnore so you can use them as local config files

Alongside with custom variables in .env file you can also specify variables for server build. Default server target is localhost:8080 even, if variables in .env files wasn't defined

PORT=8080
HOST=localhost

Default process.env object that will be available in you app after build

NODE_ENV: 'development'
VUE_ENV: 'client' // or 'server'

TypeScript

In this example you can use ES6 style in *.vue alongside with *.ts imports. TS support was configured to prevent using regular *.js files inside TS files (you still can import .vue components inside TS files). But it can be changed easily in tsconfig.json file. In same time *.ts files can be imported anywhere (JS or Vue file)

Vue components doesn't use TS since it's overcomplicated in my opinion. But it can be changed if needed just with Vue Class Component package

Jest

This example uses Jest for testing. In general it was used, just to get full stack example of project) Test files are placed in /test folder. You can run tests with

npm run test

This test example was built based on @vue/cli

SEO (page headers)

If you're using SSR then you probably need it for SEO. Question is - how to manage page headers (title, meta and etc.)

For this purpose you can use mixin DocumentHeaderMixin. It's a raw example, probably you will want to use other packages that Vue

<script>
    import {DocumentHeaderMixin} from "@/mixin"
    

    export default {
        metaInfo: {
            title: 'BookTitle',
        },
        mixins: [DocumentHeaderMixin.getProperties()]
    }
</script>

or with using mapMixins

<script>
    import {DocumentHeaderMixin} from "@/mixin"
    import {mapMixins} from "@/util"
    

    export default {
        metaInfo: {
            title: 'BookTitle',
        },
        mixins: mapMixins(
            DocumentHeaderMixin
        )
    }
</script>

Based on VUE_ENV will be exported or ClientDocumentHeaderMixin or SSRDocumentHeaderMixin

Preferable to use this mixin on Component that attached to route in router config, to prevent misunderstanding with Head info set. Depends on build (server or client) there is a different approach how to manage head information. During SSR render each component will have $ssrContext property, which can be used to set up variables in index.template.html during server render.

For Client build - you can operate with DOM itself

Build setup

Requires Node.js 7+

# install dependencies
npm install # or yarn

# serve in dev mode, with hot reload at localhost:8080
npm run dev

# build for production
npm run build

# serve in production mode
npm start

# run tests
npm run test

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].