【问题标题】:Opening index.html over file:// from Vue-cli template从 Vue-cli 模板通过 file:// 打开 index.html
【发布时间】:2018-04-29 05:25:42
【问题描述】:

当我从this Vue-cli template 运行npm run build 命令时,它会说:

提示:构建的文件旨在通过 HTTP 服务器提供服务。

通过 file:// 打开 index.html 将不起作用。

所以,问题很简单,有没有可能用file://打开index.html,它会起作用吗?

【问题讨论】:

  • 也许吧,但你为什么要这么做?
  • @akatakritos 我想把它发送给技术不高的用户,他们只需要在浏览器中打开 html 文件就足够了。
  • 有可能,您需要调整index.html中的所有资产url。我认为默认网址以/static 开头,将它们更改为static。来源:我试过一次,它成功了。
  • @EricGuan 谢谢,我试试!

标签: javascript npm webpack vue.js


【解决方案1】:

将assetsPublicPath改为'./',然后“npm run build”,然后就可以在浏览器中打开file://了。

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',     

【讨论】:

  • 谢谢,我也试试这个解决方案。
猜你喜欢
  • 2013-07-31
  • 2020-04-16
  • 1970-01-01
  • 2019-02-02
  • 2017-02-23
  • 1970-01-01
  • 2013-03-14
  • 2019-03-17
  • 2018-06-12
相关资源
最近更新 更多