9

我想使用grunt-html任务来检查我的 HTML 文件。

我在本地安装任务并按如下方式npm install grunt-html使用它:grunt.js

module.exports = 功能(咕噜声){

    grunt.loadNpmTasks('grunt-html');

    grunt.initConfig({

        htmllint:{
            全部:['*.html']
        },

    });

};

现在我想全局grunt-html安装任务。

不幸的是,在删除本地grunt-html节点模块并全局 grunt安装后,无法加载任务。跑步时grunt htmllint我得到:

>> 未找到本地 Npm 模块“grunt-html”。安装了吗?

如果我grunt.loadNpmTasks('grunt-html');grunt.js文件中删除,我会得到:

找不到任务“htmllint”。使用 --force 继续。

所以我的问题是如何使用grunt-html已安装的全局

4

1 回答 1

13

gruntjs doesn't currently support loading globally-installed grunt modules from loadNpmTasks, per the documentation of grunt.loadNpmTasks:

This plugin must be installed locally via npm, and must be relative to the grunt.js gruntfile.

Of course, if you really insist on installing it globally, a hack would be to create a symlink (ln -s) from your local node_modules directory to your global node_modules/grunt-html directory.

If you're doing module development, another alternative would be to use the under-appreciated npm link command that lets you locally install a module that exists elsewhere on you system (see npm help link for usage information).

Both of these approaches, though, don't allow you to truly install the grunt-html package globally.

于 2012-10-02T23:08:37.340 回答