当前位置:   article > 正文

.vue文件_vue项目打包后index.html文件打开空白解决方法

opening index.html over file:// won't index.html无法打开

build打包vue项目遇到的问题,如下:

1、npm run build打包项目之后,生成的dist文件里面有被压缩后的static文件跟index.html,直接打开index.html页面是空白的,还会报几个错,找不到页面路径。

原因:找到config文件下index.js,会发现build下的 assetsPublicPath:' / ' 默认为根目录,而index.html和static是在同一级目录下,因此,解决方法就是 assetsPublicPath:' ./ ' 斜杠前加一个点,表示同一级。如图:

cee273a35164d40d43e521d755df6b8c.png

2、页面可以正常打开,如果vue-router跳转路由页面无法显示

解决方法:打开index.js看路由配置,mode:' hash ' 改这个配置即可,如图:

fd0f40841c49f181c8190db70b488a49.png

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

vue静态资源打包

static path

config index.js build中:将 assetsPublicPath: '/'  改为  assetsPublicPath: './',

css静态路径

build utils.js:publicPath    return ExtractTextPlugin.extract({        use: loaders,        fallback: 'vue-style-loader',        publicPath:'../../'    })

vue-router

mode 不能为 history
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/258895
推荐阅读
相关标签
  

闽ICP备14008679号