javascript - npm install 是否也构建库?

标签 javascript jquery node.js npm

我有一个关于 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, and prepublish for anything else. You should almost never have to explicitly set a preinstall or install script. If you are doing this, please consider if there is another option. The only valid use of install or preinstall 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/

相关文章:

Javascript滚动到滚动元素

javascript - 文本区域中的两个插件

javascript - 从字符串创建对象,javascript

javascript - 如何比较javascript中的日期?

javascript - 查找日期晚于当前日期的对象

javascript - 当用户使用 jquery 不断单击按钮时需要 append html 元素

javascript - 防止元素包装

javascript - 在 Node.js 中的包含范围内生成大随机数

node.js - react : Run on production without build

javascript - node.js 中的旅程 JSON