2

我正在尝试使用 autoprefixer css 后处理器。我正在学习教程并安装了 npm。package.json使用 npm,然后我使用该文件在我的项目根目录中安装了 grunt 和 autoprefixer : https ://github.com/nDmitry/grunt-autoprefixer/blob/master/package.json

按照教程,然后Gruntfile.js我在我的项目根目录中创建了这个:

module.exports = function (grunt) {
    grunt.initConfig({
        autoprefixer: {
            dist: {
                files: {
                    'build/style.css': 'style.css'
                }
            }
        },
        watch: {
            styles: {
                files: ['style.css'],
                tasks: ['autoprefixer']
            }
        }
    });
    grunt.loadNpmTasks('grunt-autoprefixer');
    grunt.loadNpmTasks('grunt-contrib-watch');
};

之后,本教程建议使用 Grunt Watch 使用

./node_modules/.bin/grunt watch

这导致

-bash: ./node_modules/.bin/grunt: No such file or directory

我还尝试导航到项目中的 grunt 文件夹,然后显示

-bash: node_modules/grunt: is a directory

我在我的本地用户文件夹中也有一个node_modules文件夹,但是解决该文件夹 grunt 也只是告诉我它是一个文件夹。

请帮助我,为什么这不起作用?我愿意真正学习 grunt,但我什至无法使用入门指南开始...

4

2 回答 2

3

你安装了grunt-cli吗?( npm install grunt-cli -g) 当您grunt在项目根目录中运行时会发生什么?您应该运行的命令很简单grunt watch,在您的项目根目录中。

编辑:您的项目根目录还必须有一个 package.json 文件,您可以在其中定义开发依赖项;例如

{
    "name":"yourprojectname",
    "version":"0.0.1",
    "devDependencies":{
        "grunt":"*",
        "grunt-contrib-watch":"*",
        "grunt-autoprefixer":"*"
    }
}
于 2013-10-08T21:03:10.337 回答
1

如果可执行文件名称中有空格,则需要将其放在引号中

“./node_modules/.bin/grunt 监视”

否则 linux 将以 watch 作为标志运行“./node_modules/.bin/grunt”。

如果还是不行,

可能是一些问题,您的 ldconfig 未更新,文件未设置为可执行文件,或者您尝试执行命令的用户没有权限。

首先尝试运行“ldconfig”(只需键入并运行它)更多信息在这里 http://www.cyberciti.biz/tips/linux-shared-library-management.html

chmod -x 文件使它们可执行。

运气好的话?

于 2013-10-08T21:19:09.173 回答