vue项目如何部署到Tomcat中

1,假设你要访问的项目名称为‘hms’

2,在Tomcat的webapps下创建hms文件夹,

3,配置config/index.js文件,build: {} 选项里面 设置assetsPublicPath: '/hms/'

​ (解释:这里改为这个配置之后,最后编译产生的index.html中相关路径也会带上‘/hms’,不会报404的错误了)

  1. 'use strict'
  2. // Template version: 1.2.6
  3. // see http://vuejs-templates.github.io/webpack for documentation.
  4. const path = require('path')
  5. module.exports = {
  6. dev: {
  7. // Paths
  8. assetsSubDirectory: 'static',
  9. assetsPublicPath: '/',
  10. proxyTable: {},
  11. // Various Dev Server settings
  12. host: 'localhost', // can be overwritten by process.env.HOST
  13. port: 8013, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
  14. autoOpenBrowser: true,
  15. errorOverlay: true,
  16. notifyOnErrors: false,
  17. poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
  18. // Use Eslint Loader?
  19. // If true, your code will be linted during bundling and
  20. // linting errors and warnings will be shown in the console.
  21. useEslint: false,
  22. // If true, eslint errors and warnings will also be shown in the error overlay
  23. // in the browser.
  24. showEslintErrorsInOverlay: false,
  25. /**
  26. * Source Maps
  27. */
  28. // https://webpack.js.org/configuration/devtool/#development
  29. devtool: 'cheap-source-map',
  30. // CSS Sourcemaps off by default because relative paths are "buggy"
  31. // with this option, according to the CSS-Loader README
  32. // (https://github.com/webpack/css-loader#sourcemaps)
  33. // In our experience, they generally work as expected,
  34. // just be aware of this issue when enabling this option.
  35. cssSourceMap: false
  36. },
  37. build: {
  38. // Template for index.html
  39. index: path.resolve(__dirname, '../dist/index.html'),
  40. // Paths
  41. assetsRoot: path.resolve(__dirname, '../dist'),
  42. assetsSubDirectory: 'static',
  43. /**
  44. * You can set by youself according to actual condition
  45. * You will need to set this if you plan to deploy your site under a sub path,
  46. * for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/,
  47. * then assetsPublicPath should be set to "/bar/".
  48. * In most cases please use '/' !!!
  49. */
  50. // assetsPublicPath: '/',
  51. assetsPublicPath: '/hms/',
  52. /**
  53. * Source Maps
  54. */
  55. productionSourceMap: false,
  56. // https://webpack.js.org/configuration/devtool/#production
  57. devtool: 'source-map',
  58. // Gzip off by default as many popular static hosts such as
  59. // Surge or Netlify already gzip all static assets for you.
  60. // Before setting to `true`, make sure to:
  61. // npm install --save-dev compression-webpack-plugin
  62. productionGzip: false,
  63. productionGzipExtensions: ['js', 'css'],
  64. // Run the build command with an extra argument to
  65. // View the bundle analyzer report after build finishes:
  66. // `npm run build --report`
  67. // Set to `true` or `false` to always turn it on or off
  68. bundleAnalyzerReport: process.env.npm_config_report || false,
  69. // `npm run build:prod --generate_report`
  70. generateAnalyzerReport: process.env.npm_config_generate_report || false
  71. }
  72. }

使用vue-router的情况

当你在项目中使用vue-router的时候,就需要给src/router/index.js添点东西,如下面:

  1. export default new Router({
  2. mode : 'history',
  3. base: '/hms/', //添加的地方
  4. ...
  5. }

4,在项目运行“npm run build:prod”命令,生成dist文件夹,dist文件夹中包含static和index.html

5,将dist文件夹中static和index.html复制到Tomcat中webapps的hms文件夹中

6,启动Tomcat,ip:port/hms,例如:http://localhost:8080/hms/即可访问到Vue项目。

vue项目如何部署到Tomcat中的更多相关文章

  1. 【tomcat 无法部署】svn上下载的maven项目无法部署到tomcat中

    问题: svn上下载的maven项目无法部署到tomcat中,tomcat不识别项目,但是这个项目确实是web项目 发现的过程: 然后依次产看项目的编译版本: 项目的依赖架包: 才发现: 解决方法: ...

  2. MyEclipse2014中项目名更改后如何使用新的项目名部署到Tomcat中去

    在项目中调试的时候突然发现我复制的项目(项目名修改过了)部署在Tomcat中运行的时候还是显示的是原来的项目名,以至于我使用新的项目名称作为URL请求竟然是404,我去,当时感觉就不怎么好了. 当然, ...

  3. Eclipse中的普通Java项目如何部署到Tomcat中

    我现在的做法: 1.在Eclipse中配置Tomcat时,选择创建Context文件,而不是server.xml,好处是文件可以随便命名,与虚拟目录一致(即xml中的属性path).Tomcat加载项 ...

  4. 如何在IDEA中创建web项目并且部署到Tomcat中

    步骤1:File->New Project, 步骤2:选择Project SDK为1.7 -> Next -> Finish(JDK)我自己的是1.7(这里的project,跟ecl ...

  5. Eclipse中的Web项目自动部署到Tomcat

    原因 很长时间没用Eclipse了,近期由于又要用它做个简单的JSP项目,又要重新学习了,虽然熟悉的很快,但记忆总是很模糊,偶尔犯错,以前很少写博客,现在感觉还是很有必要的,编程中每个人对于犯过的错误 ...

  6. [转]Eclipse中的Web项目自动部署到Tomcat

    原文地址:http://www.cnblogs.com/ywl925/p/3815173.html 原因 很长时间没用Eclipse了,近期由于又要用它做个简单的JSP项目,又要重新学习了,虽然熟悉的 ...

  7. Eclipse中WEB项目自动部署到Tomcat

    原因 很长时间没用Eclipse了,近期由于又要用它做个简单的JSP项目,又要重新学习了,虽然熟悉的很快,但记忆总是很模糊,偶尔犯错,以前很少写博客,现在感觉还是很有必要的,编程中每个人对于犯过的错误 ...

  8. Eclipse中的Web项目自动部署到Tomcat(转)

    转自:http://www.cnblogs.com/ywl925/p/3815173.html 问题: 这里就有个问题,是怎么把Eclipse中的网站项目自动部署到tomcat中.在Eclipse中做 ...

  9. Eclipse中的Web项目自动部署到Tomcat的webapp目录下

    Eclipse中的Web项目自动部署到Tomcat   原因 很长时间没用Eclipse了,近期由于又要用它做个简单的JSP项目,又要重新学习了,虽然熟悉的很快,但记忆总是很模糊,偶尔犯错,以前很少写 ...

随机推荐

  1. pl/sql 笔记之基础(上)

    由于公司中使用 oracle,而本人对存储过程一直也懵懵懂懂,故一周时间学习了一遍 pl/sql,在此记下笔记!!! 一.前提,pl/sql 是啥? 1.PL/SQL是一种高级数据库程序设计语言,该语 ...

  2. dedecms body 输出自动替换结果。

    {dede:field.body function='str_replace("张三","李四",@me)'/} body内容中的张三全部换成了李四

  3. idea逆向生成hibernate工程

    1.创建maven工程 2.在resources下创建hibernate.cfg.xml文件 <?xml version='1.0' encoding='utf-8'?> <!DOC ...

  4. Linux 日志分析

    学会查看日志文件是一件很有意义的事,因为在Linux系统中运行的程序通常会把一些系统消息和错误消息写入对应的日志中,若是一旦出现问题,我们就可以通过查看日志来迅速定位,及时解决故障. 日志的三种类型 ...

  5. zabbix常见错误处理方式

    1.zabbix-server启动失败,我是centos7.4系统,查看/var/log/zabbix/zabbix_server.log日志显示 1516:20180816:195630.755 u ...

  6. Mac下安装svn服务器

    本文转载自http://www.cnblogs.com/czq1989/p/4913692.html Mac默认已经安装了svn,我们只需要进行配置并开启就可以了 首先我们可以验证一下是否安装了svn ...

  7. Spring中配置Hibernate事务管理

    <!-- transationManager --> <bean id="transactionManager" class="org.springfr ...

  8. 会了docker你又多了一个谈资(上)

    相信有到现在为止还是有很多同学只是听说过docker,但还不了解docker.也很想学习,但是又不知道从何入手,工作中又接触不到,而自己又懒得去翻阅各种学习资料,那么,读完本文,我保证,docker的 ...

  9. hdu1864最大报销额 01

    先把小数乘100变成整数然后处理每个发票里面可以报销的 最后自底向上DP #include <stdio.h> #include <algorithm> #include &l ...

  10. k8sDaemonSet控制器

    DaemonSet用于再集群中的全部节点上同时运行一份指定的pod资源副本,后续新加入的工作节点也会自动创建一个相关的pod对象,当从集群中移除节点时,此类pod对象也将被自动回收而无须重建.也可以使 ...