vue配置编译本地打开dist/index.html文件

vue配置编译本地打开dist/index.html文件

法一
vue项目完成后npm run build会生成dist文件,此时直接将dist文件发布到线上即可,若想本地打开dist/index.html可看,一般页面为空,或者报错找不到css和js文件,则需要更改一些路径参数,改成相对当前目录,然后再次运行npm run build 就可以在本地打开index.html

修改1:config/index.js文件的assetsPublicPath: ‘/’;===》assetsPublicPath: ‘./’;

修改2:build/webpack.base.confg.js文件的publicPath: process.env.NODE_ENV === ‘production’ ? config.build.assetsPublicPath : config.dev.assetsPublicPath===》publicPath: ‘./’

修改完成后,再次执行npm run build 后,打开dist文件夹里的index.html,大功告成!!

猜你喜欢

转载自blog.csdn.net/weixin_39897287/article/details/89643591
今日推荐