Vuejs+elementUI项目,在进行打包时,要注意的问题

注意:打包之前,需要注意修改一些地方

(1)若是前后端分离开发的,前端开发过程中可能会在api.js中设置访问路径为服务器所在电脑的ip:端口,打包前,最好将它改回localhost:8080

(2)打包后,放到服务器,可能会出现找不到页面js文件的问题,所以预先在webpack.prod.conf.js文件:

const webpackConfig/output内,添加字段publicPath:'./',效果如下

output: {
path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js'),
publicPath:'./'
},

 

1、打包命令:cnpm run build

2、打包完成后,在项目目录中会生成一个dist文件夹,内有static文件夹和index.html(测试一下,看能否直接打开index.html文件,能则打包成功)

3、index.html是服务器要用到的默认页面,static文件夹内是编译压缩后的js文件,供index.html引用

4、将static文件夹和index.html文件放到服务器的webapp/WEB-INF下,即可启动服务器。启动之前,若web.xml中设置了<servlet>的<servlet-mapping>的<url-pattern>为“/”,则要在springmvc.xml文件中添加配置访问webapp下static文件夹下的静态资源的

<mvc:annotation-driven /><mvc:resource location="/static/" mapping="/static/**"/>标签,表示DispatcherServlet不会拦截以/static开头的所有请求路径,并当做静态资源处理。若web.xml中设置的<servlet>的<servlet-mapping>的<url-pattern>为具体的匹配规则,则springmvc中不用另加配置
<mvc:annotation-driven /><mvc:resource location=“” mapping=""/>

posted on 2018-03-28 15:33  黑子菜园  阅读(4973)  评论(0编辑  收藏  举报

导航