我使用GULP创建了一个演示,但是面临运行gulp js文件的问题。
安装过程:
sudo npm init
sudo npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev
sudo npm install --save-dev gulp
控制台警告:
mnbcvd3456:glp user$ sudo npm install gulp
npm WARN package.json gulp@3.8.6 No repository field.
npm WARN install Refusing to install gulp as a dependency of itself
的package.json:
{
"name": "gulp",
"version": "3.8.6",
"description": "Gulp Demo",
"main": "index.js",
"directories": {
"doc": "doc"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "User",
"license": "ISC",
"devDependencies": {
"gulp-concat": "^2.3.3",
"gulp-jshint": "^1.7.1",
"gulp-rename": "^1.2.0",
"gulp-sass": "^0.7.2",
"gulp-uglify": "^0.3.1"
}
}
Gulp.js文件。
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
// Lint Task
gulp.task('lint', function() {
return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('js/*.js', ['lint', 'scripts']);
});
// Default Task
gulp.task('default', ['lint', 'scripts', 'watch']);
现在如果我正在尝试运行我的gulp js文件,请使用命令" gulp"。然后它产生了一个错误:
mnbcvd3456:glp user$ gulp
module.js:340
throw err;
^
Error: Cannot find module 'gulp'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/glp/gulpfile.js:5:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
答案 0 :(得分:2)
答案 1 :(得分:0)
我认为问题可能是您在同一级别上安装了两个。所以grunt和gulp都尝试访问pakage.json。
尝试将它们安装在不同的文件夹中。
此外,全局安装gulp,然后在本地不同于grunt的文件夹上安装gulp,创建一个空包,如下所示:
{
"name": "name_you_want",
"version": "0.0.1",
"devDependencies": { }
}
并为dev添加插件(在package.json所在的文件夹上的命令行:npm install --save-dev plugin_name
另外:你为什么要同时使用grunt和amp; gulp?