赞
踩
build打包vue项目遇到的问题,如下:
1、npm run build打包项目之后,生成的dist文件里面有被压缩后的static文件跟index.html,直接打开index.html页面是空白的,还会报几个错,找不到页面路径。
原因:找到config文件下index.js,会发现build下的 assetsPublicPath:' / ' 默认为根目录,而index.html和static是在同一级目录下,因此,解决方法就是 assetsPublicPath:' ./ ' 斜杠前加一个点,表示同一级。如图:
2、页面可以正常打开,如果vue-router跳转路由页面无法显示
解决方法:打开index.js看路由配置,mode:' hash ' 改这个配置即可,如图:
3、问题:
Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won't work.
解释:
npm run dev是开发环境, npm run build是生产环境, 在开发环境完成代码和测试, 之后用生产环境生成代码,执行npm run build 命令后,会生成dist目录,里边包含index.html和static文件夹。
原文:https://blog.csdn.net/zx_p24/article/details/80360312
npm run build的时候, 一开始就会提示Built files are meant to be served over an HTTP server. Opening index.html over file:// won't work., 在vue-cli的默认配置中, 把assetsPublicPath: '/'改成assetsPublicPath: './',dist文件夹里的文件必须放在服务器的根目录, 如果你想本地打开的话, 可以在npm run build完成之后执行以下命令:
E:\test\vue_new>npm install -g http-serve
config index.js build中:将 assetsPublicPath: '/' 改为 assetsPublicPath: './',
build utils.js:publicPath return ExtractTextPlugin.extract({ use: loaders, fallback: 'vue-style-loader', publicPath:'../../' })
mode 不能为 history
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。