Gulp browserify livereload

之前在browserify那个博文中介绍了gulp + browserify

不过那个配置还不能满足日常需要

搬运

https://github.com/Hyra/angular-gulp-browserify-livereload-boilerplate/blob/master/Gulpfile.js#L67

'use strict';

var gulp = require('gulp'),
jshint = require('gulp-jshint'),
browserify = require('gulp-browserify'),
concat = require('gulp-concat'),
rimraf = require('gulp-rimraf'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),//之前要安装node-sass
rsass = require('gulp-ruby-sass'), //之后还是建议安装这个 体积小 安装出错几率小
minifycss = require('gulp-minify-css'),
autoprefixer = require('gulp-autoprefixer'); // Modules for webserver and livereload
var express = require('express'),
refresh = require('gulp-livereload'),
livereload = require('connect-livereload'),
livereloadport = 35729,
serverport = 5000; // Set up an express server (not starting it yet)
var server = express();
// Add live reload
server.use(livereload({port: livereloadport}));
// Use our 'dist' folder as rootfolder
server.use(express.static('./dist'));
// Because I like HTML5 pushstate .. this redirects everything back to our index.html
server.all('/*', function(req, res) {
res.sendfile('index.html', { root: 'dist' });
}); // Dev task
gulp.task('dev', [ 'views', 'rstyles', 'lint', 'browserify'], function() { }); // Clean task
gulp.task('clean', function() {
gulp.src('./dist/views', { read: false }) // much faster
.pipe(rimraf({force: true}));
}); // JSHint task
gulp.task('lint', function() {
gulp.src('app/scripts/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
}); // Styles task
gulp.task('styles', function() {
gulp.src('app/styles/main.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer('last 4 versions', '> 1%', 'ie 8'))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist/css/')); //copy img and font
gulp.src('app/styles/imgs/*.*')
.pipe(gulp.dest('dist/css/imgs'));
gulp.src('app/styles/fonts/*.*')
.pipe(gulp.dest('dist/css/fonts'));
}); gulp.task('rstyles', function() { rsass('app/styles/main.scss',{ sourcemap: true })
.on('error', sass.logError)
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(minifycss()) // For inline sourcemaps
.pipe(sourcemaps.write()) // For file sourcemaps
.pipe(sourcemaps.write('maps', {
includeContent: false,
sourceRoot: 'app/styles'
})) .pipe(gulp.dest('dist/css')); //copy img and font
gulp.src('app/styles/imgs/*.*')
.pipe(gulp.dest('dist/css/imgs'));
gulp.src('app/styles/fonts/*.*')
.pipe(gulp.dest('dist/css/fonts'));
}); // Browserify task
gulp.task('browserify', function() {
// Single point of entry (make sure not to src ALL your files, browserify will figure it out)
gulp.src(['app/scripts/main.js'])
.pipe(browserify({
insertGlobals: true,
debug: true
}))
// Bundle to a single file
.pipe(concat('compiled.js'))
// Output it to our dist folder
.pipe(gulp.dest('dist/js/'));
}); // Views task
gulp.task('views', function() {
// Get our index.html
gulp.src('app/index.html')
// And put it in the dist folder
.pipe(gulp.dest('dist/')); // Any other view files from app/views
gulp.src('app/views/*')
// Will be put in the dist/views folder
.pipe(gulp.dest('dist/views'));
}); // Task with deps
// deps
// Type: Array
// An array of tasks to be executed and completed before your task will run. gulp.task('watch', ['lint'], function() {
// Start webserver
server.listen(serverport);
// Start live reload
refresh.listen(livereloadport); // Watch our scripts, and when they change run lint and browserify
//任意目录下的js 'app/scripts/**/*.js'
gulp.watch(['app/scripts/*.js'],[
'lint',
'browserify'
]);
// Watch our sass files
gulp.watch(['app/styles/*.scss','app/styles/**/*'], [
'rstyles'
]); gulp.watch(['app/**/*.html'], [
'views'
]); gulp.watch('./dist/**').on('change', refresh.changed); }); gulp.task('default', ['dev', 'watch']);

Gulp browserify livereload的更多相关文章

  1. 前端模块化开发学习之gulp&browserify篇

     随着web应用的发展,前端的比重占得越来越多,编写代码从而也越来越复杂.而通常我们需要将不同功能或者不同模块的代码分开写,最后在html中一起加载,这样做是可以的,但是当你需要进行维护或者是二次开发 ...

  2. 基于Gulp + Browserify构建es6环境下的自动化前端项目

    随着React.Angular2.Redux等前沿的前端框架越来越流行,使用webpack.gulp等工具构建前端自动化项目也随之变得越来越重要.鉴于目前业界普遍更流行使用webpack来构建es6( ...

  3. React+gulp+browserify模块化开发

    阅读本文需要有React的基础知识,可以在React 入门实例教程和React中文官网进行基础学习. 没有React基础也可以学习本文,本文主要不是学习React,而是gulp+browserify进 ...

  4. gulp下livereload和webserver实现本地服务器下文件自动刷新

    一.前言 node从v0.10.26升级(为了匹配autoprefixer)到v5.3.0后出现了gulp插件兼容问题,在nodejs下各种新的插件出现问题,需要重新配置.livereload实现ch ...

  5. Grunt Gulp Browserify Webpack

    Grunt 是相比后面几个更早的项目,他依赖于各种插件的配置.这是一个很好的解决方案,但是请相信我,你不会想看到一个 300 行的 Gruntfile Gulp 提供了一个不一样的解决方案,而不是依赖 ...

  6. 浏览器自动刷新——基于Nodejs的Gulp LiveReload与VisualStudio完美结合。

    本文版权桂博客园和作者吴双共同所有,转载和爬虫请注明原文地址 http://www.cnblogs.com/tdws/p/6016055.html 写在前面 大家好我是博客园的蜗牛,博客园的蜗牛就是我 ...

  7. gulp配置browserify多入口

    需要 var es = require('event-stream'); gulp.task('browserify', function(){ var files = [ { fpath: './j ...

  8. 如何在Gulp中提高Browserify的打包速度

    使用Browserify打包js时如果项目变得越来越大,编译时间就会相应变得越来越长.使用官方的插件watchify是个比较有效的提高速度方案. 提速原理 watchify的用法和gulp的watch ...

  9. 前端神器!!gulp livereload实现浏览器自动刷新

    首先gulp是基于Node的,所以确保你已经安装 node.js,在Nodejs官方网站下载跟自己操作系统相对应的安装包. 先说一下gulp安装流程: 1:全局安装gulp,操作为: npm inst ...

随机推荐

  1. CEvent,CSemaphore,CCriticalSection,CMutex

    一.用CEvent实现线程同步 事件对象(Event)是最简单的同步对象,它包括有信号和无信号两种状态.在线程访问某一资源之前,也许需要等待某一事件的发生,这时用事件对象最合适.例如,只有在通信端口缓 ...

  2. 学习C++语言的50条忠告

    50条忠告:(其中有几条觉得写的不够贴切,所以删了,发了余下的部分) 1.把C++当成一门新的语言学习: 2.看<Thinking In C++>,不要看<C++变成死相>: ...

  3. CSS3盒模型display:-webkit-box;的使用

    box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典的一个布局应用就是布局的垂直等高.水平均分.按比例划分. 目前box-flex属性还没有得到 ...

  4. Apache新版配置虚拟主机的注意事项

    1.关于没有默认索引文件(index.php或者index.html)时,列出目录:需要开启模块 LoadModule autoindex_module modules/mod_autoindex.s ...

  5. Java编程中提高性能的几点建议

    尽量减少对变量的重复计算 如 for(int i=0;i<list.size();i++) 应该改为 for(int i=0,len=list.size();i<len;i++) 并且在循 ...

  6. 3D项目处理点选操作步骤

     1.用notepad++模型的obj格式文件,查找到模型各个部分的名称,命名规则:g mesh......,把名字改为规则命名.  2.选择处理 #ifdef _DEBUG #pragma comm ...

  7. linux基础--chkconfig 详解

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...

  8. javascript将异步校验表单改写为同步表单

    同步表单校验的缺点 响应错误信息时,需要重新加载整个页面(虽然有缓存,客户端仍然需要通过http协议对比每个文件是否有更新,以保持文件最新) 服务器响应错误以后,用户之前所输入的信息全部丢失了,用户需 ...

  9. 将String类型的数字字符转换成int

    java.lang.Integer.parseInt(String) public static int parseInt(String s) throws NumberFormatException ...

  10. iOS6和iOS7代码的适配(3)——坐标适配

    由于iOS7里面status bar和视图是重叠在一起了,所以应用的y坐标就没法和以前一致了,需要重新计算设定.基本上,你的应用用Xcode5运行一下就能看见这个问题,这里写了一个最简单的例子,一个V ...