我正在尝试使用 autoprefixer css 后处理器。我正在遵循教程并安装了 npm。然后,我使用 npm 使用该 package.json
文件在项目根目录中安装了 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,但我什至无法开始使用入门指南...
最佳答案
您安装了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":"*"
}
}
关于javascript - Node.js/Grunt - 无法运行 Grunt 的 watch - 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258223/