gulp#4.0
gitbook教程:
https://dragon8github.gitbooks.io/gulp-webpack/content/an-zhuang-gulp-4-0.html
gulpfile.js
// cnpm i -g gulpjs/gulp#4.0 && cnpm i gulpjs/gulp#4.0 gulp-sass fs-extra gulp-autoprefixer gulp-sourcemaps browser-sync gulp-ejs gulp-rename gulp-babel babel-core babel-preset-env babel-preset-stage-2 gulp-typescript typescript -S
const gulp = require('gulp')
const babel = require('gulp-babel')
const ts = require('gulp-typescript')
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer')
const sourcemaps = require('gulp-sourcemaps')
const rename = require('gulp-rename')
const browserSync = require('browser-sync').create()
const fse = require('fs-extra')
const path = require('path'); // 初始化
gulp.task('init', function () {
// 获取当前文件路径(兼容windows)
var PWD = process.env.PWD || process.cwd();
var dirs = ['dist',
'dist/html',
'dist/css',
'dist/img',
'dist/js',
'src','src/sass',
'src/js',
'src/img',
'src/sprite'
]; dirs.forEach(function (item,index) {
try {
// 使用mkdirSync方法新建文件夹
fse.mkdirSync(path.join(PWD + '/'+ item));
} catch (err) {
console.log(err.message);
}
})
}) // 编译typescript
gulp.task('ts', function () {
return gulp.src('./src/js/*.ts')
.pipe(ts({
'noImplicitAny': true,
'declaration': true,
'target': 'es5'
}))
.js.pipe(gulp.dest('./dist/js/'))
}) // 编译babel
gulp.task('babel', function () {
return gulp.src('./src/js/*.es')
.pipe(sourcemaps.init())
.pipe(babel({
presets: [
[
'env',
{
'targets': {
'browsers': ['last 5 versions', 'ie >= 8']
}
}
],
'babel-preset-stage-2'
]
}))
.pipe(sourcemaps.write('./map')) // 这里的地址是相对于gulp.dest输出目录的,并且必须在gulp.dest输出之前执行
.pipe(gulp.dest('./dist/js')) }) // 编译sass
gulp.task('sass', function () {
return gulp.src('./src/sass/*.scss')
.pipe(sourcemaps.init())
.pipe(autoprefixer({
browsers: ['last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'],
cascade: true,
remove: true
}))
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('./map')) // 这里的地址是相对于gulp.dest输出目录的,并且必须在gulp.dest输出之前执行
.pipe(gulp.dest('./dist/assets/css'))
}) // watch
gulp.task('watch', function () {
// 监听重载文件
var files = [
'src/html/*.html',
'src/css/*.css',
'src/js/*.es',
'src/js/*.ts',
'src/sprite/*.png'
]
browserSync.init(files, {
server: {
baseDir: './src/html/',
}
})
gulp.watch('./src/sass/*.scss', gulp.series('sass'))
gulp.watch('./src/js/*.es', gulp.series('babel'))
gulp.watch('./src/js/*.js', gulp.series('babel'))
gulp.watch('./src/html/*.html').on('change', browserSync.reload)
}) // 开发环境
gulp.task('dev', gulp.series('init', gulp.parallel('sass', 'babel', 'ts'), 'watch'))
gulp#4.0的更多相关文章
- Gulp 从0开始
http://www.w3ctech.com/topic/134 (该文章有很多错误) http://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97 ...
- gulp#4.0 Did you forget to signal async completion?
异常截图 解决方案: https://stackoverflow.com/questions/36897877/gulp-error-the-following-tasks-did-not-compl ...
- gulp顺序执行任务
gulp的任务的执行是异步的. 所以,当我写完一系列的任务,准备一股脑地执行. # gulp.task('prod', ['clean', 'compass', 'image', 'style', ' ...
- 前端工程筹建NodeJs+gulp+bower
1.安装nodejs nodejs 官网下载安装文件 安装完成之后,在命令窗口执行,(显示nodejs版本) 和(显示npm版本)可以使用这两个命令查看是否安装成功: node -v npm -v 2 ...
- 前端工程搭建NodeJs+gulp+bower
需要node.npm的事先安装!! 1.nodejs安装程序会在环境变量中添加两个变量: 系统环境变量中:path 增加C:\Program Files\nodejs\ 因为在该目下存在node.ex ...
- gulp实用配置(2)——中小项目
上一篇的gulp配置很简单,主要就是为了demo的查看和调试,这一篇则会相对详细一些,包括压缩合并打时间戳等. 在互联网环境比较好的城市,需要多人协作的,大一点的项目应该都用上了模块化(这里主要指co ...
- gulp的安装与使用【附配置代码】
备忘 1.配置 下载安装node.js node -v //检查nodejs版本 npm(nodejs package manager)nodejs包管理工具 nodejs完毕在命令行输入np ...
- gulp学习-metamask前端使用
https://www.gulpjs.com.cn/docs/getting-started/ ,这个是3.9.0版本 后面发现安装的版本是4.0.0,看下面这个: https://github.co ...
- 使用gulp 合并压缩打包,实时监控文件,实现本地server
今天不讲webpack,就说说gulp是怎么进行压缩合并打包 首先你的安装gulp : npm install gulp -g --save-dev 然后最基本的你因该知道gulp 的四个方法, gu ...
随机推荐
- GO语言基础之reflect反射
反射reflection 1. 反射可以大大的提高程序的灵活性,使得 interface{} 有更大的发挥余地 2. 反射使用 TypeOf 和 ValueOf 函数从接口中获取目标对象信息 3. 反 ...
- 如何监控执行的SQL语句?
环境: SQL Server 2012. 打开SQL Server Profiler. 在菜单中选择New Trace, 连接上SQL Server. 在弹出的窗口中选择Event selection ...
- easyui tree带checkbox实现单选
<ul id="regionTree"></ul> $('#regionTree').tree({ cascadeCheck: false, //onlyL ...
- 【网络文摘】Androidguy:当你的才华还无法撑起你的野心时,那么应该静下心来学习
[序] 2013年12月初,接到51CTO的邀请写一篇关于挨踢人物传记的邀请.尽管写文章对我已不是什么新鲜事.数年来写的书和博客至少也在600万字以上.不过基本都是与技术有关的.写传记这还是头一次,也 ...
- HTML5游戏,五子棋
在线演示 本地下载 最近html5的游戏还真是不少,这种在线游戏既简单又有趣.收藏几个在午休时间娱乐一下.何乐而不为呢?喜欢研究的可以下载代码看看.超级推荐!
- VB 中窗口发现冲突名称,将使用名称...怎么解决?
首先上图: 刚開始敲机房收费系统的时候就出现过这样的情况,当时有八个之多. 解决方法: (1)对窗口进行重命名(比如将frmGongZuoJiLu改成frmGongzuojilu),于是从8个错误降低 ...
- 破解OfficeVBA密码的方法
我自己找到一个office的VBA加密方法,然后再去找一个方法来破解密码,好像有点自相矛盾啊. 如果excel文件是xls或xlm格式(如果不是请转化成此种方法),则可使用以下代码: '移除VBA编码 ...
- android 如何连真机测试
1. 设置android手机为USB调试模式.步骤: menu---> 设置 ---> 应用程序 ---> 开发 , 选择[USB调试] 2. 用USB连接手机和电脑,并确保成功.步 ...
- Throwing cards away I uva1594
Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the t ...
- sp_trace_setfilter sqlserver筛选跟踪或跟踪过滤
sp_trace_setfilter sp_trace_setfilter [ @traceid = ] trace_id , [ @columnid = ] column_id , [ @logic ...