笔记 npm
1. npm (node package management):node 的包管理
(1):Use npm to install, share, and distribute code;用node可以安装,分享,构建代码
ex: npm install gulp 举例npm安装gulp
npm install gulp -g
npm 全局安装:为什么要全局安装?
因为如果全局安装的话,可以在电脑任何地方用;ex:npm install http-server -g
npm install gulp --save-dev npm安装gulp保存到此设备
为什么后面要加 --save-dev ?
如果npm install 后面加 --save-dev,可以在package.json里面的devDependencies 可以看到 包管理:gulp-imagemin,gulp-scss,gulp;
(2) manage dependencies in your projects;
npm install gulp --save-dev
gulp file.js
vargulp =require('gulp');
varsass =require('gulp-sass');
varimagemin =require('gulp-imagemin');
gulp.task('sass',function() {
returngulp.src('./src/scss/*.scss')
.pipe(sass().on('error',sass.logError))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('sass:watch',function() {
gulp.watch('./src/scss/*.scss',['sass']);
});
gulp.task('package-js',function() {
gulp.src('./src/js/*.js')
.pipe(gulp.dest('./dist/js'));
});
gulp.task('package-html',function() {
gulp.src('./src/index.html')
.pipe(gulp.dest('./dist'));
});
gulp.task('package-image',function() {
gulp.src('./src/assets/*.png')
.pipe(gulp.dest('./dist/assets'));
});
gulp.task('develop',['sass','package-js','package-html','package-image']);
(3) and share & receive feedback with others.