【问题标题】:No client/build folder created when i run "npm run build" with vuejs app as frontend当我使用 vuejs 应用程序作为前端运行“npm run build”时没有创建客户端/构建文件夹
【发布时间】:2021-06-21 02:39:23
【问题描述】:

我正在尝试将客户端和服务器代码从单个 git 存储库部署到 heroku。当我运行“npm run build”时,我得到了这个:

但是没有创建文件夹,所以我无法部署应用程序。

这是我的 package.json 脚本

"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"

},

这是我的代码,让我们的 Express 服务器知道为我们的项目提供服务:

(process.env.NODE_ENV === "production") {
  app.use(express.static(__dirname + "/public", "../../client/build"));
  app.get("*", (req, res) =>
    res.sendFile(
      path.join(__dirname, "../../client/build", "/public/index.html")
    )
  );
}

【问题讨论】:

  • 上面写着The ..\server\public directoy is ready to be deployed.将你的快递服务器调整到那个路径。

标签: node.js vue.js heroku


【解决方案1】:

安装 Heroku CLI

创建一个 static.json 文件:

{
  "root": "dist",
  "clean_urls": true,
  "routes": {
    "/**": "index.html"
  }
}

将 static.json 文件添加到 git

git add static.json
git commit -m "add static configuration"

部署到 Heroku

heroku login
heroku create
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static
git push heroku master

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 2020-12-25
    相关资源
    最近更新 更多