vue項目如何部署到Tomcat中

1涩僻,假設(shè)你要訪問的項目名稱為‘hms’

2晌涕,在Tomcat的webapps下創(chuàng)建hms文件夾狐赡,

3撞鹉,配置config/index.js文件,build: {} 選項里面 設(shè)置assetsPublicPath: '/hms/'

? (解釋:這里改為這個配置之后颖侄,最后編譯產(chǎn)生的index.html中相關(guān)路徑也會帶上‘/hms’,不會報404的錯誤了)

'use strict'
// Template version: 1.2.6
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {
  dev: {
    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8013, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: true,
    errorOverlay: true,
    notifyOnErrors: false,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: false,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-source-map',

    // 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
  },

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',

    /**
     * You can set by youself according to actual condition
     * You will need to set this if you plan to deploy your site under a sub path,
     * for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/,
     * then assetsPublicPath should be set to "/bar/".
     * In most cases please use '/' !!!
     */
    // assetsPublicPath: '/',
    assetsPublicPath: '/hms/',

    /**
     * Source Maps
     */

    productionSourceMap: false,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: 'source-map',

    // 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 || false,

    // `npm run build:prod --generate_report`
    generateAnalyzerReport: process.env.npm_config_generate_report || false
  }
}


使用vue-router的情況
當你在項目中使用vue-router的時候鸟雏,就需要給src/router/index.js添點東西,如下面:

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

4览祖,在項目運行“npm run build:prod”命令孝鹊,生成dist文件夾,dist文件夾中包含static和index.html

5展蒂,將dist文件夾中static和index.html復(fù)制到Tomcat中webapps的hms文件夾中

6又活,啟動Tomcat,ip:port/hms玄货,例如:http://localhost:8080/hms/即可訪問到Vue項目皇钞。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市松捉,隨后出現(xiàn)的幾起案子夹界,更是在濱河造成了極大的恐慌哮塞,老刑警劉巖碌上,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件忘苛,死亡現(xiàn)場離奇詭異绊寻,居然都是意外死亡,警方通過查閱死者的電腦和手機复斥,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進店門营密,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人目锭,你說我怎么就攤上這事评汰。” “怎么了痢虹?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵被去,是天一觀的道長。 經(jīng)常有香客問我奖唯,道長惨缆,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任丰捷,我火速辦了婚禮坯墨,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘病往。我一直安慰自己捣染,他們只是感情好,可當我...
    茶點故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布荣恐。 她就那樣靜靜地躺著液斜,像睡著了一般累贤。 火紅的嫁衣襯著肌膚如雪叠穆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天臼膏,我揣著相機與錄音硼被,去河邊找鬼。 笑死渗磅,一個胖子當著我的面吹牛嚷硫,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播始鱼,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼仔掸,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了医清?” 一聲冷哼從身側(cè)響起起暮,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎会烙,沒想到半個月后负懦,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體筒捺,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年纸厉,在試婚紗的時候發(fā)現(xiàn)自己被綠了系吭。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,133評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡颗品,死狀恐怖肯尺,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情躯枢,我是刑警寧澤蟆盹,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站闺金,受9級特大地震影響逾滥,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜败匹,卻給世界環(huán)境...
    茶點故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一寨昙、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧掀亩,春花似錦舔哪、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至炼七,卻和暖如春缆巧,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背豌拙。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工陕悬, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人按傅。 一個月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓捉超,卻偏偏與公主長得像,于是被迫代替她去往敵國和親唯绍。 傳聞我的和親對象是個殘疾皇子拼岳,可洞房花燭夜當晚...
    茶點故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容