如何将 npm 项目部署到 gh-pages
How to deploy npm project to gh-pages
我正在尝试使用 npm 将网站部署到 gh-pages。我正在使用 blain HTML 和 CSS 以及异步 javascript。我没有使用任何 SPA 框架(反应或 angular)。
我目前正在使用精简版服务器进行开发和 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\_logs20-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\_logs20-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
我发现您不需要构建脚本或预部署脚本。它们没有必要使用,因为我的网站是静态的,我可以直接导航到构建文件夹,它会正常工作。
我修改了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 个页面。
我正在尝试使用 npm 将网站部署到 gh-pages。我正在使用 blain HTML 和 CSS 以及异步 javascript。我没有使用任何 SPA 框架(反应或 angular)。 我目前正在使用精简版服务器进行开发和 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\_logs20-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\_logs20-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
我发现您不需要构建脚本或预部署脚本。它们没有必要使用,因为我的网站是静态的,我可以直接导航到构建文件夹,它会正常工作。
我修改了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 个页面。