为什么会想这么做呢?
因为武汉的同事反馈说NPM安装过慢,那么我这里尝试给了一些解决方案,但是需要使用命令
这个时候我就在想既然用了命令行,但是还是需要手动输入,这个时候就免不了出错。那么有没有一种可能我直接给个可执行文件,一键配置呢?
全局安装zx
Requirement: Node version >= 16.0.0
npm i -g zx
运行方法(2种):
第一种:直接使用zx运行
zx ./script.mjs
第二种:分配运行权限
chmod +x ./script.mjs
./script.mjs
有的大聪明就要提问了:“老师,我就喜欢使用node xxx
来运行我的脚本。我该怎么写呢?”
对此我也贴心的给出了答案
npm install zx // 本地安装
node ./script-node.mjs
遗憾的是目标的最后一步打包成可执行文件没有完成
对应的工具pkg.js
可以打包,但是实际测试win
版本的时候一闪而过,对应的macos
错误描述也超出了我的认知范围。
只能说留一个遗憾了