欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue項目webpack打包部署到服務(wù)器的實例詳解

 更新時間:2017年07月17日 11:31:19   投稿:lqh  
這篇文章主要介紹了Vue項目webpack打包部署到服務(wù)器的實例詳解的相關(guān)資料,需要的朋友可以參考下

Vue項目webpack打包部署到服務(wù)器

這篇博文主要說的就是我今天遇到的問題,而且在經(jīng)過我的詢問,好多人在打包部署的時候都遇到了一些問題,下面就來說下,如何將Vue項目放置在服務(wù)器上,這里以Tomcat為例。

必須要配置的就是/config/index.js

在vue-cli webpack的模板下的/config/index.js,我們可以看到assetsPublicPath這個鍵,并且這個東西還出現(xiàn)了兩次,我第一次打包的時候,只是修改了最下面的assetsPublicPath,將它從'/'變?yōu)榱?/,然后我就執(zhí)行了npm run build,打包成功之后,可以看到項目中會多出來一個文件夾,就是dist,里面有一個static文件夾和index.html,然后我就將dist目錄下的文件拷貝到Tomcat服務(wù)器下,會發(fā)現(xiàn)訪問到的是一個空白頁面,但是當我把它放在..\webapps\ROOT目錄下,它就可以訪問了

Tomcat下面的目錄結(jié)構(gòu):

但是這肯定是不行的,然后我就開始尋找答案,也根據(jù)別人的一些步驟做了下來,后來發(fā)現(xiàn)還是有一些問題的,沒有辦法訪問到主頁面,雖然吧,一直都沒成功,但是我也沒放棄,然后就綜合了一下問答里面別人說的,進行了幾次嘗試,最后成功了。(給大家一個小建議:別放棄就好)。

下面的就是我的config/index.js的配置:

// 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: './',
  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: {},
  // 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
 }
}

可以發(fā)現(xiàn),我就改了兩處,就是assetsPublicPath所對應(yīng)的值,我這里用的是./,我也用webapps下的命的項目名試過,只是沒得到我想要的結(jié)果,后來我還是改成了./

使用vue-router的情況

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

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

然后執(zhí)行npm run dev,將打包后的文件放在Tomcat的目錄下的WebApps下的ttms中,然后,就可以訪問到了:http://localhost:8080/ttms/

以上就是關(guān)于Vue項目webpack打包部署到服務(wù)器的實例詳解的資料,關(guān)于Vue的開發(fā)文章本站還很多,希望大家搜索參閱,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論