【问题标题】:How to deploy npm project to gh-pages如何将 npm 项目部署到 gh-pages
【发布时间】:2020-09-17 23:10:20
【问题描述】:

我正在尝试使用 npm 将网站部署到 gh-pages。我正在使用纯 HTML 和 CSS 以及异步 javascript。我没有使用任何 SPA 框架(反应或角度)。 我目前正在将 lite 服务器用于开发目的和 gh-pages 包。

我正在尝试使用以下命令部署 src 文件夹 npm run deploy

它失败了,因为没有指定构建脚本。 我的问题是我应该在构建脚本中写什么?

当我尝试运行npm run deploy 时,它显示以下错误


'src' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! AmrAhmed@1.0.0 build: `src`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the AmrAhmed@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Amr\AppData\Roaming\npm-cache\_logs\2020-05-30T11_30_29_824Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! AmrAhmed@1.0.0 predeploy: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the AmrAhmed@1.0.0 predeploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Amr\AppData\Roaming\npm-cache\_logs\2020-05-30T11_30_29_869Z-debug.log

在使用react的类似项目中,构建脚本有以下react-scripts build

这是我的 package.json 文件

{
    "name": "AmrAhmed",
    "version": "1.0.0",
    "description": "",
    "main": "truffle.js",
    "directories": {
        "test": "test"
    },
    "scripts": {
        "dev": "lite-server",
        "test": "echo \"Error: no test specified\" && exit 1",
        "build": "src",
        "predeploy": "npm run build",
        "deploy": "gh-pages -d src"
    },
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "gh-pages": "^3.0.0",
        "lite-server": "^2.5.4"
    }
}

election folder content

src folder content

【问题讨论】:

    标签: github npm github-pages package.json


    【解决方案1】:

    我发现您不需要构建脚本或预部署脚本。它们是不必要的,因为我的网站是静态的,我可以直接导航到构建文件夹,它会正常工作。

    我已将 config.json 文件修改为如下

    {
        "name": "AmrAhmed",
        "version": "1.0.0",
        "description": "",
        "main": "truffle.js",
        "directories": {
            "test": "test"
        },
        "scripts": {
            "dev": "lite-server",
            "test": "echo \"Error: no test specified\" && exit 1",
            "deploy": "gh-pages -d src"
        },
        "author": "",
        "license": "ISC",
        "devDependencies": {
            "gh-pages": "^3.0.0",
            "lite-server": "^2.5.4"
        }
    }
    

    运行命令 npm run build

    它将被部署到 Github 页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 2022-01-23
      • 2022-01-20
      • 2019-11-13
      • 1970-01-01
      • 2017-08-20
      • 2019-01-25
      相关资源
      最近更新 更多