HTML/Css デザイン講義 という本です。
gulpやnodeは準備できました。
エラー内容と対策 教えていただきたいです。
以下エラーです。
PS C:\Users\mac\Documents\CssCafe> gulp
[12:55:06] Using gulpfile ~\Documents\CssCafe\gulpfile.js
[12:55:06] Starting 'image'...
[12:55:08] Starting 'js'...
[12:55:08] Starting 'bs'...
[12:55:08] Finished 'bs' after 205 ms
[12:55:08] Starting 'scss'...
[12:55:09] 'scss' errored after 301 ms
[12:55:09] Error: Cannot find module 'gulp-sass' from 'C:\Users\mac10\Documents\CssCafe'
at Function.module.exports [as sync] (C:\Users\mac10\Documents\CssCafe\node_modules\resolve\lib\sync.js:43:15)
at requireFn (C:\Users\mac10\Documents\CssCafe\node_modules\gulp-load-plugins\index.js:74:25)
at Object.get [as sass] (C:\Users\mac10\Documents\CssCafe\node_modules\gulp-load-plugins\index.js:117:41)
at Gulp.<anonymous> (C:\Users\mac10\Documents\CssCafe\gulpfile.js:31:15)
at module.exports (C:\Users\mac10\Documents\CssCafe\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\Users\mac10\Documents\CssCafe\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (C:\Users\mac10\Documents\CssCafe\node_modules\orchestrator\index.js:214:10)
at C:\Users\mac10\Documents\CssCafe\node_modules\orchestrator\index.js:279:18
at finish (C:\Users\mac10\Documents\CssCafe\node_modules\orchestrator\lib\runTask.js:21:8)
at module.exports (C:\Users\mac10\Documents\CssCafe\node_modules\orchestrator\lib\runTask.js:60:3)
[12:55:09] Finished 'js' after 1000 ms
[12:55:09] gulp-imagemin: Minified 0 images
[12:55:09] Finished 'image' after 2.8 s
[Browsersync] Access URLs: |
---|
Local: http://localhost:3000 External: http://192.168.56.1:3000
UI: http://localhost:3001
UI External: http://192.168.56.1:3001 |
---|
[Browsersync] Serving files from: ./ |
以下 gulpfile.jsです。
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var paths = {
"htmlSrc" : "./.html",
"scssSrc" : "./src/scss/**/.scss",
"jsSrc" : "./src/js/.js",
"jsLib" : "./src/js/lib/.js",
"imgSrc" : "./src/images/**",
"rootDir" : "./dist/",
"imgDir" : "./dist/images/",
"jsDir" : "./dist/js/"
}
gulp.task('bs', function() {
browserSync.init({
server: {
baseDir: "./"
},
notify : true,
xip : false
});
});
gulp.task('scss', function() {
return gulp.src(paths.scssSrc)
.pipe($.sourcemaps.init())
.pipe($.sass()).on('error', $.sass.logError)
.pipe($.autoprefixer({
browsers: ['last 2 versions']
}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(paths.rootDir + 'css'))
.pipe($.rename({
suffix: '.min'
}))
.pipe($.csso())
.pipe(gulp.dest(paths.rootDir + 'css'))
.pipe(browserSync.reload({
stream: true,
once : true
}));
});
gulp.task('bs-reload', function() {
browserSync.reload();
});
gulp.task('image', function() {
return gulp.src(paths.imgSrc)
.pipe($.changed(paths.imgDir))
.pipe($.imagemin({
optimizationLevel: 3
}))
.pipe(gulp.dest(paths.imgDir));
});
gulp.task('js', function() {
return gulp.src([paths.jsLib, paths.jsSrc])
.pipe($.uglify({preserveComments: 'license'}))
.pipe($.concat('main.min.js', {newLine: '\n'})
)
.pipe(gulp.dest(paths.jsDir));
});
gulp.task('default', ['image', 'js', 'bs', 'scss', 'bs-reload'], function() {
gulp.watch([paths.htmlSrc], ['bs-reload']);
gulp.watch([paths.scssSrc], ['scss']);
gulp.watch([paths.imgSrc], ['image']);
gulp.watch([paths.jsSrc], ['js']);
});