简体   繁体   English

gulp-browserify如何在同一目录中生成文件

[英]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. 如果您能告诉我们您的testsFiles变量包含什么,这将testsFiles ,因为您正在处理路径问题,而您的问题很可能在那里。

Anyway... usually Gulp does not forget the original path of your source files and considers them when creating output files. 无论如何...通常Gulp不会忘记源文件的原始路径,并且在创建输出文件时会考虑它们。 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. 您可以进一步扩展它:如果输入目录是./app/ ,则应将./app/作为目标目录。

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. 我随机猜测您的testsFiles指向的目录与目的地不同。 So the contents of them would be necessary to determine your problem. 因此,它们的内容对于确定您的问题将是必要的。 This has nothing to do with Browserify at all. 这与Browserify完全无关。

Btw., speaking of which: Consider dropping gulp-browserify , as it has been blacklisted a while ago 顺便说一句,谈到:考虑删除gulp-browserify ,因为它早已被列入黑名单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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