我是靠谱客的博主 勤奋老虎,这篇文章主要介绍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内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部