当前位置:   article > 正文

Vue——vue项目打包完点击index.html打开_vue打包file本地index.html打开项目(不需要起服务)

vue打包file本地index.html打开项目(不需要起服务)

在Vue项目打包完之后会出现:Tip: built files are meant to be served over an HTTP server. Opening index.html over file:// won't work.
1、用http-server解决。
在本地安装一个简易的http服务器。

 npm install http-server -g
  • 1

然后在打包好的dist包中运行:hs
2、修改项目配置,因为vue-cli的默认配置中, publishPath是用绝对目录, 所以dist文件夹里的文件必须放在服务器的根目录。
打开项目中的config,在index.js修改以下配置。

 assetsPublicPath: './',
  • 1

在这里插入图片描述
然后打开build,找到utils.js中的以下配置,修改如下:

  publicPath:'../../',
  • 1

在这里插入图片描述

特别注意:要想直接点开index.html运行,必须去掉vou-router中的:
mode:‘history’
在这里插入图片描述

在vue-cli4.0版本上,需要在根目录新建vue.config.js文件,然后添加以下配置:

module.exports = {
  //基本路径
  publicPath: "./",
  //输出文件目录
  outputDir: "dist",
  //webpack-dev-server相关配置
  devServer: {
    // port: 8011,
    host: "localhost",
    open: true, //配置游览器自动访问
  },
};

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号