I have been trying to work out a way to gzip my build files after a build within a github action. My build doesn't automatically do this, and I'm not sure where or when it should be zipping.
My action has a working run command that builds the project, but then the zipping either fails or just doesn't work depending on how I run it.
This is how I've tried lately:
- name: Build
run: |
npm ci
npm run build --prod --aot
- name: GZIP
run: |
npm install gzip-cli
gzip ./dist/*.js -k -9
I'm sure the answer here is either "you can't do that" or "you can't do that", but I don't know where to go from here. My server does not zip the files itself and I'm not sure how to make github do it. I need all of the js
files to have gz
files.
I have tried using gzipper
as well as gzip-cli
and the console usually outputs this:
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.
It looks like it installs just fine, but then it shows the command can't be found (whether gzipper or gzip-cli).
If I were to use plain old gzip
, I don't get any error. It runs, but does not actually zip anything. Could it be github is temporarily storing the files somewhere before uploading it?
With the current method you're using to install gzip-cli
or gzipper
, they'll be saved to the current project's node_modules
folder. Their executables will also be installed in node_modules/.bin
(which can be found by running npm bin
). However, your project dependency executables will typically not be available in the PATH
environment variable unless you install them globally.
From the docs for the bin
field for a dependency's package.json
:
On install, npm will symlink that file into
prefix
/bin
for global installs, or./node_modules/.bin/
for local installs.
As such, you should either:
Install the dependencies globally with the -g
flag. If npm's .bin
directory is included in the PATH
, you can easily execute the commands.
Run the commands with $(npm bin)/
appended to the command:
$(npm bin)/gzip ./dist/*.js -k -9
Or add a script that does the same thing. Typically npm scripts will have dependency executables available to them in the PATH
environment variable :
{ "scripts: { "gzip-files": "gzip ./dist/*.js -k -9" }, "dependencies": { "gzip-cli": "/* version range */" } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.