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的更多相关文章
随机推荐
- maven(一)
Maven的简介 什么是maven 是apache下的一个开源项目,是纯java开发,并且只是用来管理java项目的 Maven好处 普通的传统项目 maven项目 分析:maven项目为什么这么小? ...
- 短信验证登陆-中国网建提供的SMS短信平台
一.JAVA发送手机短信常见的有三种方式(如下所列): 使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册 使用短信mao的方式进行短信 ...
- 20165308《Java程序设计》第7周学习总结
20165308<Java程序设计>第7周学习总结 教材学习内容总结 第十一章:JDBC与MySQL数据库 MySQL数据库管理系统 启动MySQL数据库服务器 MySQL客户端管理工具 ...
- [转]DB2错误代码大全
DB2 SQLSTATE 消息 异常 一2008-03-31 13:17SQLSTATE 消息本节列示 SQLSTATE 及其含义.SQLSTATE 是按类代码进行分组的:对于子代码,请参阅相应的表. ...
- TypeScript 之 声明文件的使用
https://www.tslang.cn/docs/handbook/declaration-files/consumption.html 下载 在TypeScript 2.0以上的版本,获取类型声 ...
- TypeScript 与 es6 写法的区别
import 方式 ts 默认对于 commonjs 的模块是这样加载的:import * as React from 'react'; es6:import React from 'react'; ...
- 在vue-cli 2.x 项目中,引入stylus的全局CSS变量
出处:https://blog.csdn.net/weixin_39378610/article/details/81140358
- git add -A /git add -u/git add .的用法
git的指令详解 在git中有好多的指令,但是今天这几个指令就很容易忘记而且还容易混淆 git add -u <==> git add –update 提交所有被删除和修改的文件到数据暂存 ...
- sqoop上传数据到hdfs,并用hive管理数据。
sqoop导入mysql数据表到HDFS中sqoop import --connect jdbc:mysql://master:3306/test --username root --password ...
- textwrap 笔记
import textwrap s = """Look into my eyes, look into my eyes, the eyes, the eyes, the ...