首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将npm项目部署到gh-pages

如何将npm项目部署到gh-pages
EN

Stack Overflow用户
提问于 2020-05-30 19:43:55
回答 1查看 353关注 0票数 1

我正在尝试使用npm将一个网站部署到gh-pages。我使用blain HTML、CSS和异步javascript。我没有使用任何SPA框架(react或angular)。我目前正在使用lite server进行开发,并使用gh-pages包。

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

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

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

代码语言:javascript
复制
'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文件

代码语言:javascript
复制
{
    "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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-30 21:58:29

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

我已经修改了config.json文件,如下所示

代码语言:javascript
复制
{
    "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页面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62101924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档