首页 > 代码库 > gulp_css2js
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。