我是靠谱客的博主 勤奋老虎,最近开发中收集的这篇文章主要介绍vue项目如何部署到Tomcat的二级目录,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1,假设你要访问的项目名称为‘hb’
2,在Tomcat的webhbs下创建hb文件夹,
3,配置config/index.js文件,设置assetsPublicPath: '/hb/'
4,在项目运行“npm run build:prod”命令,生成dist文件夹,dist文件夹中包含static和index.html
5,将dist文件夹中static和index.html复制到Tomcat中webapps的hb文件夹中
6,启动Tomcat,ip:port/hb,例如:http://localhost:8081/hb/即可访问到Vue项目。
 

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')

module.exports = {
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/hb',
    productionSourceMap: true,
    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  },
  dev: {
    env: require('./dev.env'),
    port: 8080,
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    //proxyTable: {},

    proxyTable: {
      '/api': {
        target: 'http://localhost:9000',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    },

    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  }
}

最后

以上就是勤奋老虎为你收集整理的vue项目如何部署到Tomcat的二级目录的全部内容,希望文章能够帮你解决vue项目如何部署到Tomcat的二级目录所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部