博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bootstrap 4 gulp 配置
阅读量:6930 次
发布时间:2019-06-27

本文共 2100 字,大约阅读时间需要 7 分钟。

最近想写个项目,由于之前一直写后端,很少接触前端,所以这次来好好学一下前端。看了下Yii框架,它自带了Bootstrap框架,最开始想的是怎么快速写个页面,哪知道这个就像剥洋葱一样,就剥到了学习构建工具的阶段。

说个很沮丧的消息,等我把gulp这套工具调通了后,发现Github上居然有很多这样的模板了!废了我3天时间来搞这个东西。给个关键词:bootstrap 4 gulp boilerplate。额,以及还有一个网站,这是我读完bootstrap的文档后发现的:。

在项目目录下的babelln/gulpfile.babel.js:

// 如果要编译babel可以启用// const babel = require('gulp-babel');// const concat = require('gulp-concat');// const uglify = require('gulp-uglify');const del = require("del");const gulp = require("gulp");const browserSync = require("browser-sync");const sassCompile = require("gulp-sass");const server = browserSync.create();const paths = {  scripts: {    src: "src/scripts/*.js",    dest: "dist/scripts"  },  css: {    src: "src/scss/*.scss",    dest: "dist/css"  }};// 定义清理方法,会删除dist目录const clean = () => del(["dist"]);// 定义需要拷贝到dist目录的文件,一般APP最终使用的JS和CSS文件在这个目录中const scriptFiles = [  paths.scripts.src,  "node_modules/bootstrap/dist/js/bootstrap.min.js",  "node_modules/jquery/dist/jquery.min.js",  "node_modules/popper.js/dist/umd/popper.min.js"];// 编译babel文件的时候使用// function scripts() {//   return gulp.src(paths.scripts.src, { sourcemaps: true })//     .pipe(babel())//     .pipe(uglify())//     .pipe(concat('index.min.js'))//     .pipe(gulp.dest(paths.scripts.dest));// }// 将源代码文件复制到目的地,中间可以加入其他处理程序function scripts() {  return gulp.src(scriptFiles).pipe(gulp.dest(paths.scripts.dest));}// 重启web服务function reload(done) {  server.reload();  done();}// 编译sass文件,在dist/css目录产生结果文件function sass() {  return gulp    .src(["node_modules/bootstrap/scss/bootstrap.scss", paths.css.src])    .pipe(sassCompile())    .pipe(gulp.dest(paths.css.dest));}// 服务初始化,以当前目录babelln/作为网站根目录function serve(done) {  server.init({    server: {      baseDir: "./"    }  });  done();}// 定义需要监控的文件const watches = [paths.scripts.src, "*.html", paths.css.src];// 定义watch函数,它监控watches定义的文件,然后顺序执行这些方法const watch = () => gulp.watch(watches, gulp.series(scripts, sass, reload));// 再包装一层,整个流程就是清理,编译脚本,编译sass,初始化web服务,启动监控const dev = gulp.series(clean, scripts, sass, serve, watch);// 暴露默认方法给外部程序exports.default = dev;

这个就是根据gulp官方的模板来捏的,最终还算是可以工作。

最后放个效果图^^

编译界面:

clipboard.png

转载地址:http://uqvjl.baihongyu.com/

你可能感兴趣的文章
outlook已停止工作,以及word有的内容不显示。
查看>>
大湿教我写程序(3)之自动补全(屌丝没有春天)篇
查看>>
centos6.5 安装hadoop2.7.6 1master2node
查看>>
轻松掌握shell编程中数组的常见用法及示例
查看>>
hive自定义函数
查看>>
ccnp
查看>>
NFS 服务配置
查看>>
python安装mysqldb
查看>>
c++语言实现装饰模式代码示例
查看>>
ubuntu pecl安装swool
查看>>
国外排名前20的设计博客和网站资源
查看>>
012 出牌显示
查看>>
如果要求精确的答案,请避免使用float和double
查看>>
jqueryUI左右拖动效果扩展
查看>>
开源文化
查看>>
大学生软件设计大赛功能需求
查看>>
module_param()
查看>>
编辑测试文章
查看>>
从网站被篡改看数据备份的重要性
查看>>
C语言经典例题一
查看>>