【发布时间】:2020-04-26 10:11:00
【问题描述】:
我一直在尝试在 github 操作中构建后找到一种方法来 gzip 我的构建文件。我的构建不会自动执行此操作,我不确定应该在何处或何时进行压缩。
我的操作有一个构建项目的有效运行命令,但随后压缩失败或根本不起作用,具体取决于我的运行方式。
这是我最近尝试的方式:
- name: Build
run: |
npm ci
npm run build --prod --aot
- name: GZIP
run: |
npm install gzip-cli
gzip ./dist/*.js -k -9
我确定这里的答案要么是“你不能那样做”要么是“你不能那样做”,但我不知道从这里去哪里。我的服务器本身不压缩文件,我不知道如何让 github 做到这一点。我需要所有js 文件才能拥有gz 文件。
我试过使用gzipper 和gzip-cli,控制台通常会输出这个:
npm install gzipper
gzipper --exclude jpg,jpeg,png,svg ./dist
shell: /bin/bash -e {0}
npm WARN karma-jasmine-html-reporter@1.5.1 requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.
+ gzipper@3.4.2
updated 1 package and audited 19029 packages in 11.676s
33 packages are looking for funding
run `npm fund` for details
found 2 high severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
/home/runner/work/_temp/96763ca6-0048-4812-a8bb-72bf33d14fcc.sh: line 2: gzipper: command not found
##[error]Process completed with exit code 127.
看起来它安装得很好,但是它显示找不到命令(无论是 gzipper 还是 gzip-cli)。
如果我使用普通的旧 gzip,我不会收到任何错误。它运行,但实际上并没有压缩任何东西。难道是github在上传之前将文件临时存储在某个地方?
【问题讨论】:
-
究竟什么是“不工作”?你是什么意思它失败取决于你如何运行它;您还尝试了哪些其他方式来运行该命令?您还确定
gzip命令在路径上吗?假设您在 linux 环境中执行此操作,您是否可以运行命令command -v gzip来查看您正在运行哪个gzip命令(如果有)?请包括所有这些作为您的问题的更新 -
@smac89 谢谢你的评论,我马上更新答案
-
您应该尝试全局安装它。默认情况下,如果未指定
-g标志,npm 将自动在本地node_modules下安装您的依赖项。具有可执行文件的依赖项将在node_modules/.bin中提供其可执行文件,可以通过执行$(npm bin)找到。 -
您在工作流程中使用什么跑步者? (例如
ubuntu-latest、macos-latest) -
@Edric 我在做
runs-on: ubuntu-latest
标签: node.js github yaml github-actions