gulp_css2js
var gulp = require('gulp');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var cssmin = require('gulp-minify-css');
var through = require('through-gulp');
var fs = require('fs');
function gulp_css2js() {
return through(function (file, enc, cb) {
if (file.isBuffer()) {
var cssContents = file.contents;
cssContents = cssContents.toString();
cssContents = cssContents.replace(/'/gm, '"');
var insertStyleCode = '' +
'function insertStyleCode(styleCode) {' +
' var styleNode = document.createElement("style");' +
' styleNode.type = "text/css";' +
' if (styleNode.styleSheet) { styleNode.styleSheet.cssText = styleCode;' +
' } else { styleNode.innerHTML = styleCode;}' +
' document.getElementsByTagName("head")[0].appendChild(styleNode);' +
'}' +
'';
var jsContents = '' +
'(function(){' +
' ' + insertStyleCode +
' var styleCode = \'' + cssContents + '\' ;' +
' insertStyleCode(styleCode);' +
'})();';
file.contents = new Buffer(jsContents);
this.push(file);
cb();
} else {
cb();
}
});
}
gulp.task('soma_news_ad_css',function(){
return gulp.src('./events/soma_news_ad/soma_news_ad.css')
.pipe(cssmin())
.pipe(gulp_css2js())
.pipe(rename('soma_news_ad_css.js'))
.pipe(gulp.dest('./events/soma_news_ad/dist'));
});
gulp.task('soma_news_ad',['soma_news_ad_css'],function () {
var jsArray = [
'./events/soma_news_ad/soma_news_ad.js',
'./events/soma_news_ad/dist/soma_news_ad_css.js'
];
return gulp.src(jsArray)
.pipe(concat('soma_news_ad_pack.js'))
.pipe(gulp.dest('./events/soma_news_ad/dist'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./events/soma_news_ad/dist'));
});
gulp_css2js的更多相关文章
随机推荐
- gunicorn工作原理
gunicorn工作原理 Gunicorn“绿色独角兽”是一个被广泛使用的高性能的Python WSGI UNIX HTTP服务器,移植自Ruby的独角兽(Unicorn )项目,使用pre-fork ...
- linux日志管理
//有关当前登录用户的信息记录在文件utmp中 //登录进入和退出纪录在文件wtmp中 [root@bogon python]# who //who命令查询utmp文件并报告当前登录的每个用户 /va ...
- MySQL--派生表临时结果集中的AutoKey
在某些场景中,需要对派生表生成临时结果集进行materialized,如果该临时结果集中包含索引键,那么查询有可能通过该索引键来进行优化. 如对下面查询: SELECT T2.purpose_code ...
- day3 python学习
---恢复内容开始--- 运算 在Python中有很多种运算方法,我们在这里只是先说比较运算,逻辑运算,赋值运算,算数运算 在这里要记住 == 判断两个值是否相等 是比较运算符 >= 是否大 ...
- TS学习之for..of
for..of会遍历可迭代的对象,调用对象上的Symbol.iterator方法(可迭代对象,数组,字符串等) let arr = ["hello", "ts" ...
- 对象的继承(prototype)
修改构造函数的原型对象,批量修改所有子对象的继承关系
- attr()、prop()、css() 的区别
.attr( ) 可以设置元素的属性(也就是给元素新增加一个原来并不存在的属性)也可以获取元素的本来就有的属性以及额外设置的属性.如果要获取的属性没有设置,那么获取到的结果是 undefined; . ...
- Spring Schedule实现定时任务
applicationContext.xml 1. 增加配置 <!-- 开启定时任务 --> <task:annotation-driven /> <!-- 开启注解 - ...
- 【设计模式】JDK源码中用到的设计模式
https://blog.csdn.net/angjunqiang/article/details/42061453 https://blog.csdn.net/baiye_xing/article/ ...
- Linux内核移植到JZ2440
一.准备工作:1.Linux内核:Linux2.6.22.6,可从www.kernel.org上下载:2.交叉工具编译链:arm-linux-gcc-3.4.5-glibc-2.3.6:3.yaffs ...