安装单个包后运行脚本

安装单个包后运行脚本

本文介绍了在 npm 安装单个包后运行脚本(如 postinstall)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始玩 Snowpack.它采用了与 Webpack 不同的方法,在安装后立即捆绑各个包.

I'm starting to play around with Snowpack. It takes a different approach from Webpack by bundling individual packages right after they're installed.

问题"是,当我安装一个包时,我必须首先运行 npm install --save my-package 然后我必须用 npx snowpack 手动打包它代码>.Snowpack 文档 提到我可以包含一个 prepare 运行 npm install 后将 snowpack 一切的脚本,但这不适用于单个包,仅适用于所有依赖项的通用 npm install在我的 package.json 中.据我所知,npm 文档中提到的所有 npm 钩子都是这种情况.

The "issue" is, when I install a package I have to first run npm install --save my-package and then I have to manually pack it with npx snowpack. The Snowpack docs mention that I can include a prepare script that would snowpack everything after running npm install but that doesn't apply to individual packages, just on a generic npm install of all dependencies in my package.json. As far as I can tell, this is the case for all npm hooks mentioned in the npm docs.

有什么方法可以让我在安装单个软件包时自动运行脚本?我能想到的唯一方法是覆盖安装脚本并向其中添加一些内容.GitHub 或其他地方是否有此类示例?

Is there any way I can automatically run a script whenever I install an individual package? The only way I can think of would be to overwrite the install script and add something to it. Are there any examples of this on GitHub or elsewhere?

更新:为了澄清起见,每次我使用 --save 安装新包时,我都想运行 npx snowpack 但最好是不带 --save-dev 或不带 --save.对于任何包,这永远不会有所不同.这将特定于某个存储库/项目,而不是我系统上的全局.

Update: For clarification, I'd like to run npx snowpack every time I install a new package with --save but preferably not with --save-dev or without --save. This will never be different for any package. This will be specific to a certain repo/project, not global on my system.

在简单地运行 npm install 之后运行 snowpack 是不够的,因为你可以通过挂钩到 postinstallrelease.此外,我想确保开发我的项目的开发人员可以像往常一样使用 npm install --save newdep,然后 snowpack 将运行.我不想要求开发人员使用自定义的 named 脚本.

It is not sufficient to run snowpack after simply running npm install as you would get by hooking into postinstall or release. Additionally, I want to make sure developers working on my project can use npm install --save newdep as they normally would and then snowpack will run. I do not want to require devs to use a custom named script.

推荐答案

使用较新版本的 Snowpack (>=2),您可以运行 snowpack dev,它会监视您的 npm_modules 用于构建新模块的文件夹.

With newer versions of Snowpack (>=2) you can run snowpack dev and it will watch your npm_modules folder for new modules to build.

这篇关于在 npm 安装单个包后运行脚本(如 postinstall)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:59