简体   繁体   中英

gulp-browserify How can i generate the file in the same directory

I have diferent's files, i want to browserify them in isolation and leave the result of each file on the same folder of the source file. For example given the following tree structure:

\subfolderOne
    fileToBeBrowserified.js
\subfolderTwo
    \subfolderTwo_one
        fileToBeBrowserified.js
    \subfolderTwo_two
        fileToBeBrowserified.js

The result should be:

\subfolderOne
    fileToBeBrowserified.js
    resultFile.js
\subfolderTwo
    \subfolderTwo_one
        fileToBeBrowserified.js
        resultFile.js
    \subfolderTwo_two
        fileToBeBrowserified.js
        resultFile.js

I have tried the following code, but the files get generated on the root not on it's own folder.

gulp.src(testsFiles)
.pipe(browserify({
        insertGlobals: false,
        debug:true
    })
)
.pipe(rename ({extname:'.Bundle.js'}))
.pipe(gulp.dest('./'))

Any help would be welcomed, thanks in advance.

It would help alot if you could tell us what your testsFiles variable contains, since you're dealing with path problems, and your problem will most likely be there.

Anyway... usually Gulp does not forget the original path of your source files and considers them when creating output files. So if you tell your app to get everything from ./ then ./ is the correct output directory to be.

You can extend this further: If your input directory is ./app/ , then you should take ./app/ as your destination directory.

So for example this:

gulp.task('scripts', function() { return gulp.src('./app/**/*.js') .pipe(browserify({ insertGlobals: false, debug: true })) .pipe(rename({ extname: '.bundle.js' })) .pipe(gulp.dest('./app')); });

works like a charm for your problem. I randomly guess that your testsFiles point to a different directory then your destination. So the contents of them would be necessary to determine your problem. This has nothing to do with Browserify at all.

Btw., speaking of which: Consider dropping gulp-browserify , as it has been blacklisted a while ago

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM