我有一个关于 npm 的问题。 also tried on reddit .
我们以jQuery npm为例举个例子。
当我 npm install jquery
时,我在我的 node_modules
文件夹中找到了一个 jquery
文件夹,
我在其中找到了 dist
,尽管它在 .gitignore
中被忽略了。
下面是包的脚本:
"scripts": {
"build": "npm install && grunt",
"start": "grunt watch",
"test": "grunt && grunt test"
},
Grunt 用于构建 - 未在我的 node_modules
中找到(使用 npm5)。
duck 是从哪里来的 dist
文件夹??
以jQuery为例,虽然我见过很多这样的包。
提前致谢
最佳答案
Does npm install also builds the library?
总的来说:视情况而定。您可以指定 install
scripts
section 中的脚本在package.json
文件,当有人运行 npm install <package>
时执行,但不建议这样做:
Don't use
install
. Use a.gyp
file for compilation, andprepublish
for anything else. You should almost never have to explicitly set apreinstall
orinstall
script. If you are doing this, please consider if there is another option. The only valid use ofinstall
orpreinstall
scripts is for compilation which must be done on the target architecture.
特别是对于 jQuery,它似乎是在发布到 npm 之前(手动)构建的。 jQuery 使用 grunt建立图书馆。这将生成 dist
文件夹:
build: {
all: {
dest: "dist/jquery.js",
minimum: [
"core",
"selector"
],
更重要的是,jQuery 有一个 .npmignore
文件,这意味着此文件已用于 .gitignore
在 npm 上发布包时。如您所见,它不排除 dist/
文件夹,因此在发布到 npm 时会包含该文件夹。
所以似乎有人运行这些步骤来发布新版本的 jQuery:
npm run build
npm publish
关于javascript - npm install 是否也构建库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34994619/