前提

安装好nodejs并配置好环境变量,最好是 node10,https://nodejs.org/en/download/

参考我之前的文章

debian安装nodejs

Yarn && npm设置镜像源

开始

初始化项目

首先创建一个文件夹webapp,并使用yarn初始化

yarn init

完整命令

➜  main git:(j2v8-version) ✗ mkdir webapp
➜  main git:(j2v8-version) ✗ cd webapp
➜  webapp git:(j2v8-version) ✗ pwd
/mnt/c/Users/Terwer/IdeaProjects/jvue/src/main/webapp
➜  webapp git:(j2v8-version) ✗ yarn init
yarn init v1.13.0
question name (webapp): jvue
question version (1.0.0):
question description: Next light-weight,responsive project With Vue,webpack,Spring Boot and eclipse j2v8 Script engine for server-side-rendering
question entry point (index.js): server.js
question repository url:
question author: Terwer
question license (MIT):
question private:
success Saved package.json
Done in 317.09s.
➜  webapp git:(j2v8-version) ✗

初始化类库

➜  webapp git:(j2v8-version) ✗ yarn
yarn install v1.13.0
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Saved lockfile.

安装项目依赖

yarn add vue vue-router

安装webpack打包

yarn add -D webpack webpack-cli

项目结构

所有源码放在src子文件下

app.js : 项目入口

import Vue from "vue";
import App from "./App.vue";
new Vue({
  el: "#app",
  render: h => h(App)
});

App.vue: 根组件

<template>
  <div>
    <h1>Hello World!</h1>
  </div>
</template>

pages: 页面,每个文件对应一个路由

components: 子组件

router: 路由配置

store: vuex配置(稍后添加)

config: 项目配置

eslint美化代码

yarn add -D  eslint babel-eslint eslint-config-google eslint-loader eslint-plugin-html eslint-plugin-vue @vue/eslint-config-prettier

.eslintrc.js

const config = require("./config");

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    "google",
    "eslint:recommended",
    "plugin:vue/essential",
    "@vue/prettier"
  ],
  // required to lint *.vue files
  plugins: ["html"],
  settings: {
    "import/resolver": {
      webpack: {
        config: "build/webpack.base.conf.js"
      }
    }
  },
  // add your custom rules here
  rules: {
    "no-console": "off",

    // allow debugger; instruction during development
    "no-debugger": config.isProduction ? 2 : 0,

    "no-unused-vars": [
      2,
      {
        vars: "local",
        args: "none"
      }
    ],
    semi: ["error", "always"],

    // don"t require comma in the last line of an object/dictionary declaration
    "comma-dangle": ["error", "never"],

    // force space after and before curly braces in object/dict declarations
    "object-curly-spacing": ["error", "always"],

    // ignore max-len for comments
    "max-len": [
      "error",
      {
        code: 100,
        ignoreComments: true,
        ignoreTrailingComments: true,
        ignoreUrls: true,
        ignoreStrings: true
      }
    ],

    // force "===" in comparisons when ambiguous
    eqeqeq: ["error", "smart"],

    // force double quotes
    quotes: ["error", "double"],

    "require-jsdoc": 1,

    "new-cap": ["error", { capIsNew: false }]
  },
  parserOptions: {
    sourceType: "module",
    parser: "babel-eslint"
  }
};

package.json 添加命令

 "lint": "eslint --ext .js,.vue,.html --ignore-path .gitignore --ignore-pattern !.eslintrc.js --ignore-pattern !.babelrc.js . --fix --color",

webpack项目打包配置

安装 vue-loader

yarn add -D vue-loader vue-template-compiler vue-style-loader css-loader

首先配置非服务端渲染

安装 webpack-dev-server 以及 html-webpack-plugin

yarn add -D webpack-dev-server html-webpack-plugin

webpack.nossr.config.js

const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
  mode: "development",
  node: {
    fs: "empty",
    module: "empty"
  },
  entry: "./src/app.js",
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: "vue-loader"
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      template: "./public/index.ejs",
      title: "Next Vue SSR Project for Java j2v8 Script engine",
      favicon: "./public/favicon.ico",
      inject: true
    })
  ],
  devServer: {
    host: "0.0.0.0",
    port: 8888
  }
};

package.json 添加命令

 "nossr": "webpack-dev-server --config build/webpack.nossr.config.js --progress"

查看结果

运行 yarn nossr ,查看结果

Vue SSR 配合Java的Javascript引擎j2v8实现服务端渲染2创建Vue2+webpack4项目的更多相关文章

  1. Vue SSR配合Java的Javascript引擎j2v8实现服务端渲染1概述

    原文地址 http://www.terwergreen.com/post/vue-ssr-j2v8-1.html 初步实现方案探索(Node环境) // 第 1 步:创建一个 Vue 实例 const ...

  2. Vue SSR 配合Java的Javascript引擎j2v8实现服务端渲染3配置webpack支持ssr

    安装 cross-env yarn add -D cross-env 安装 html-webpack-plugin yarn add -D html-webpack-plugin 安装 webpack ...

  3. Vue SSR 配合Java的Javascript引擎j2v8实现服务端渲染4支持构建bundle

    安装 webpack-node-externals yarn add -D webpack-node-externals

  4. Vue、Nuxt服务端渲染,NodeJS全栈项目,面试小白的博客系统~~

    Holle,大家好,我是李白!! 一时兴起的开源项目,到这儿就告一段落了. 这是一个入门全栈之路的小项目,从设计.前端.后端.服务端,一路狂飙的学习,发量正在欣喜若狂~~ 接触过WordPress,H ...

  5. Vue(服务端渲染)

    一.前言 1.服务端渲染图解                                                 2.简介服务端渲染                             ...

  6. 【分享】Vue 资源典藏(UI组件、开发框架、服务端、辅助工具、应用实例、Demo示例)

    Vue 资源典藏,包括:UI组件 开发框架 服务端 辅助工具 应用实例 Demo示例 element ★11612 - 饿了么出品的Vue2的web UI工具套件 Vux ★7503 - 基于Vue和 ...

  7. 使用 PHP 来做 Vue.js 的 SSR 服务端渲染

    对于客户端应用来说,服务端渲染是一个热门话题.然而不幸的是,这并不是一件容易的事,尤其是对于不用 Node.js 环境开发的人来说. 我发布了两个库让 PHP 从服务端渲染成为可能.spatie/se ...

  8. 服务端渲染 数据驱动 不是渲染后的网页,而是一个由html和Javascript组成的app ssr 隐藏接口服务器

    小结: 1. 服务端渲染主要的工作是把组件渲染为服务器端的 HTML 字符串,将它们直接发送到浏览器,最后将静态标记"混合"为客户端上完全交互的应用程序. 服务器给到客户端的已经是 ...

  9. Vue 爬坑之路(十一)—— 基于 Nuxt.js 实现服务端渲染(SSR)

    直接使用 Vue 构建前端单页面应用,页面源码时只有简单的几行 html,这并不利于网站的 SEO,这时候就需要服务端渲染 2016 年 10 月 25 日,zeit.co 背后的团队对外发布了一个 ...

随机推荐

  1. o2o的关健在于线下!

    其实,说到底,O2O不是那么简单的.一堆空降兵和一群自以为是的风投都把所有的线下产业想简单了.没有真正的去了解和体验这个产业,就动不动一个小点子,创新一个小平台就妄想能改变或替代中国某某产业.看看这几 ...

  2. Atitit 提升效率 界面gui方面的前后端分离与cbb体系建设 规范与推荐标准

    Atitit 提升效率 界面gui方面的前后端分离与cbb体系建设 规范与推荐标准 1. 界面gui方面的前后端分离重大意义1 2. 业务逻辑也适当的迁移js化1 3. 常用分离方法2 3.1. 页面 ...

  3. python thrift使用实例

    前言 Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架.本文将从 Python开发人员角度简单介绍 Apache Thrift 的架构.开发和使 ...

  4. Multiplication of numbers

    Questin: There is an array A[N] of N numbers. You have to compose an array Output[N] such that Outpu ...

  5. phpcmsv9 管理加密解密

    例子:  密码:123123  encrypt:Jiu5He 第一步:  md5("123456")="4297f44b13955235245b2497399d7a93& ...

  6. 【iCore4 双核心板_ARM】例程二十:LWIP_TCP_CLIENT实验——以太网数据传输

    实验现象: 核心代码: int main(void) { system_clock.initialize(); //ϵͳʱÖÓ³õʼ»¯ led.initialize(); //LED³õʼ ...

  7. Repeater数据控件的两个重要事件ItemDataBound 和 ItemCommand

    1 ItemDataBound:数据绑定的时候(正在进行时)发生. 2 ItemCommand :用来响应Item模板中的控件的事件. 如下代码 aspx代码: [html] view plain c ...

  8. mysql 修改表的每个列的字符类型

    #!/bin/shfor i in $(mysql -uroot -p112358s uarticles_2019 -e "show tables;"|egrep -v Table ...

  9. Java知多少(91)对话框

    对话框是为了人机对话过程提供交互模式的工具.应用程序通过对话框,或给用户提供信息,或从用户获得信息.对话框是一个临时窗口,可以在其中放置用于得到用户输入的控件.在Swing中,有两个对话框类,它们是J ...

  10. C语言中的字符串处理库函数介绍与实现

    一.介绍 本文将主要介绍字符串处理库函数中的strlen.strcpy.strcat.strcmp.atoi等,主要由<string.h>头文件提供. 二.strlen函数:求字符串的长度 ...