2017-10-16 7 views
0

위한 맞춤 출력 파일 경로 설정 값을 지정 출력 파일 경로 ./lib/bundle.js이다.위의 예에서, 출력 파일 경로 (번들)</p> <pre><code>node node_modules/browserify/bin/cmd src/index -o lib/bundle.js </code></pre> <p>을 지정 <code>-o</code>에 CLI 사용 browserify

그러나, 나는 CLI를 사용하지 않을, 내가 JS SDK를 사용하려면 :

const browserify = require('browserify'); 

    const b = browserify(); 
    b.add('./src/index.js'); 
    b.bundle(/* Where to specify the output filepath, is it here */) 
    .pipe(/* or here*/) 

내 머리 때문에이 라이브러리의 휴식 것입니다. 솔직히 Webpack 문서가 더 좋습니다.

어떤 도움을 당신이 Gulp 빌드 시스템을 사용하는 일이 경우 표준 파일 스트림

const browserify = require('browserify'); 
const fs = require('fs'); 

browserify() 
    .add('./src/index.js') 
    .bundle() 
    .pipe(fs.createWriteStream('./lib/bundle.js')); 

답변

1

그냥 pipe 감사, 당신은 이런 식으로 할 수도 있습니다.

(내 자신의 환경에서이 작업을 수행하는 데 도움이 된 그의 article에 대한 Dan Tello에게 감사드립니다!).

이 접근법은 vinyl-source-stream이라는 다른 노드 모듈의 도움을 사용합니다. 이 도우미 모듈을 사용하면 더 이상 사용되지 않는 gulp-browserify 패키지에 의존하지 않으므로 최신 바닐라 browserify 패키지를있는 그대로 사용할 수 있습니다.

var gulp = require('gulp'); 

// add in browserify module to bundle the JS 
// We can use this directly instead of 'gulp-browserify' with help 
// from 'vinyl-source-stream' 
var browserify = require('browserify'); 

// Add in vinyl-source-stream to help link browserify and gulp streams 
var source = require('vinyl-source-stream'); 

gulp.task('browserify',() => { 

    return browserify('./js/main.js') // source to compile 
     .bundle() // compile it... 
     .pipe(source('popup.js')) // pipe to output file 
     .pipe(gulp.dest('./js/')); // put output back into ./js/ 
});