1.先决条件
- 需要会爬梯子,因为需要用npm。
- 你的域名和ip地址已经解析好了
2.项目打包
- 打包代码:npm run build
- 打包后复制dist中所有文件,在tomcat中的webapps下一个新建项目名(例如demo),复制到demo中,重启。
- 如果出现空白页,修改config下的index.js文件。将assetsPublicPath: '/'修改成assetsPublicPath: ‘./’。
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
productionSourceMap: false,
// 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']
},
3.tomcat端口默认为8080解决
其实我觉最后通过http:/xxx.cn:8080/demo这样的访问方式真的好low,所以这个问题必须解决。所以以下是这个问题的解决方案。找到tomcat的安装路径,打开conf文件夹找到server.xml中将代码中port=“8080”修改成port=“80”
<Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"
redirectPort="8443" />