2016-04-08 10 views
0

"Derlemek" ve base64 biçimine dönüştürmem gereken birkaç html şablonum var. Derleme ile JS ve CSS satır içi satır içi ve sonra base64 biçimine dönüştürmeyi kastediyorum.Dosya içeriğini base64 olarak derlemek için bir gulp eklentisi var mı?

gulp-base64'u denedim, ancak bu yalnızca CSS'deki görüntüler için çalışır. Herhangi bir fikir?

Düzenleme: Her dosyayı tek tek işlemek için gulp-foreach kullanabilir ve her dosyanın içeriğini base64 biçimine dönüştürmek için Buffer kullanabilirsiniz. Ben böyle bir şey yapabileceğini biliyorum:

> console.log(new Buffer("Hello World").toString('base64')); 
SGVsbG8gV29ybGQ= 
> console.log(new Buffer("SGVsbG8gV29ybGQ=", 'base64').toString('ascii')) 
Hello World 

Ama dosya akışları (Ben vinil deniyor düşünüyorum) yudumda henüz nasıl çalıştığını oldukça iyi anlamıyorum çünkü bunu nasıl gerçekten emin değilim. Herhangi bir yardım büyük takdir edilecektir.

cevap

0

Sorunu aynı soruna bir çözüm ararken buldum.

'use strict'; 
module.exports = 'data:application/pdf;base64,... base64 encoded string...'; 
:

// import the appropriate plugins 
// 
const each = require('gulp-each'); 
const htmlToJs = require('gulp-html-to-js'); 

// I'm compiling a couple of small PDF files 
// 
gulp.task('compile:pdf',() => 
    gulp.src('./files/**/*.pdf') 
     // use gulp-each to iterate over the files & convert the 
     // files to a base64-encoded data URL 
     // 
     .pipe(each((content, file, callback) => { 
      const output = `data:application/pdf;base64,${new Buffer(content).toString('base64')}`; 

      // the first arg in this callback is the error; the second 
      // is the content to pass along via the stream 
      // 
      callback(null, output) 
     })) 

     // use gulp-html-to-js to convert the data URL to a JS module 
     // which can be imported 
     // 
     .pipe(htmlToJs()) 

     // and set the destination... 
     // 
     .pipe(gulp.dest('./client/modules/helpers/files')) 
); 

Sonuçta şuna benzer içerikli bir JS dosyasıdır: Ben o paketi kullanmıyordu rağmen gulp-foreach kullanmak Öneriniz, çözüm götürdü

İlgili konular