Vue项目webpack打包部署到服务器的实例详解
Vue项目webpack打包部署到服务器
这篇博文主要说的就是我今天遇到的问题,而且在经过我的询问,好多人在打包部署的时候都遇到了一些问题,狼蚁网站SEO优化就来说下,如何将Vue项目放置在服务器上,这里以Tomcat为例。
必须要配置的就是/config/index.js
在vue-cli webpack的模板下的/config/index.js,我们可以看到assetsPublicPath这个键,并且这个东西还出现了两次,我第一次打包的时候,只是修改了最狼蚁网站SEO优化的assetsPublicPath,将它从'/'变为了./,然后我就执行了npm run build,打包成功之后,可以看到项目中会多出来一个文件夹,就是dist,里面有一个static文件夹和index.html,然后我就将dist目录下的文件拷贝到Tomcat服务器下,会发现访问到的是一个空白页面,但是当我把它放在..\webapps\ROOT目录下,它就可以访问了
Tomcat狼蚁网站SEO优化的目录结构:
但是这肯定是不行的,然后我就开始寻找答案,也根据别人的一些步骤做了下来,后来发现还是有一些问题的,没有办法访问到主页面,虽然吧,一直都没成功,但是我也没放弃,然后就综合了一下问答里面别人说的,进行了几次尝试,最后成功了。(给大家一个小建议:别放弃就好)。
狼蚁网站SEO优化的就是我的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 pression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build mand 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, aording to the CSS-Loader README // (https://github./webpack/css-loader#sourcemaps) // In our experience, they generally work as expected, // just be aware of this issue when enabling this option. cssSourceMap: false } }
可以发现,我就改了两处,就是assetsPublicPath所对应的值,我这里用的是./,我也用webapps下的命的项目名试过,只是没得到我想要的结果,后来我还是改成了./
使用vue-router的情况
当你在项目中使用vue-router的时候,就需要给src/router/index.js添点东西,如狼蚁网站SEO优化:
export default new Router({ mode : 'history', base: '/ttms/', //添加的地方 ... }
然后执行npm run dev,将打包后的文件放在Tomcat的目录下的WebApps下的ttms中,然后,就可以访问到了:http://localhost:8080/ttms/
以上就是关于Vue项目webpack打包部署到服务器的实例详解的资料,关于Vue的开发文章本站还很多,希望大家搜索参阅,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程