如何将NPM项目部署到gh页

时间:2020-05-30 11:43:54

标签: github npm github-pages package.json

我正在尝试使用npm将网站部署到gh页。我正在使用简单的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

1 个答案:

答案 0 :(得分:0)

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

我已将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页面。