Code Monkey home page Code Monkey logo

vue-ssr's Introduction

vue-ssr

基于vue-cli3搭建的vue项目改造成SSR服务端渲染项目

项目启动

# 下载依赖
yarn

#本地调试页面
yarn serve

# 打包
# PS: 打包后可以把dist目录下的index.html文件删了,避免直接访问到了该html文件
yarn build:win

# 启动SSR服务端渲染项目
node server.js

yarn serve本地调试:
image

yarn build:win & node server.js
image

项目结构

1、resource文件夹为README.md说明图片 2、server文件夹为测试文件夹,可删除,查看效果

cd server
node test.js

node server.js

image

image
image

项目搭建

1、Vue SSR官网API:https://ssr.vuejs.org/zh/
2、可先使用vue2按照以下方式搭建项目,根据需求是否选择typescript:https://segmentfault.com/a/1190000019905650

3、SSR项目改造博文参考:

4、项目说明:

  • 新增安装的包
vue-server-renderer

# server.js 需要
express / koa koa-router koa-static koa-send

# 用于package.json构建命令
cross-env 

# vue.config.js配置文件需要
webpack-node-externals lodash.merge
  • 项目文件
├─dist 打包后文件夹
│  ├─......
│  ├─vue-ssr-client-manifest.json
│  └─vue-ssr-server-bundle.json
├─public
├─src
│    ├─assets
│    ├─components
│    ├─router 改成导出一个 createRouter 函数
│    ├─store  改成导出一个 createStore 函数
│    ├─views
│    ├─App.vue
│    ├─entry-client.js 新增 挂载客户端应用程序 文件
│    ├─entry-server.js 新增 挂载服务端端应用程序  文件
│    ├─index.template.html 新增 html
│    └─main.js 改成导出一个 createApp 函数
├─server.js 新增SSR服务端渲染配置文件
└─vue.config.js 添加配置文件
  • package.json命令说明
# 将服务器端Json文件移出dist
move dist\\vue-ssr-server-bundle.json bundle

# 将服务器端Json文件移回dist
move bundle dist\\vue-ssr-server-bundle.json

# 删除dist目录下index.html文件
rimraf dist\\index.html

vue-ssr's People

Contributors

ccyinghua avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.