Gulp & Webpack: webpack-stream working with a nonexistent file

In this task Gulpand Webpackintegrated Webpack-stream, therefore, instructions for Webpackare included in gulpfile.js. I am currently using webpack 3.4.1 and webpack-stream 4.0.0.

const   gulp = require('gulp'),
        gulpIf = require('gulp-if'),
        webpackStream = require('webpack-stream'),
        webpack = webpackStream.webpack,
        named = require('vinyl-named');

I need to define conditional output and then create a function inside gulp.dest(). Thanks to vynil-namedus, we do not need to determine entry points, however, in order to determine the output condition, we need to know where the file was received from (it can be paths publicor admin, for example).

It is gulp.dest()said internally that the file was received from C:\MyIde\projects\testProj\someEntryPoint.js, but in fact this file is located in C:\MyIde\projects\testProj\source\public\js\someEntryPoint.js:

gulp.task('webpack', function(){

    /*  Entry points locations:
        C:\MyIde\projects\testProj\source\public\js
        C:\MyIde\projects\testProj\source\admin\js  */

    return gulp.src('source')
        .pipe(named())
        .pipe(webpackStream())
        .pipe(gulp.dest( file => {

            console.log('path: '+ file.path);
            // Output to console: "path: C:\MyIde\projects\testProj\someEntryPoint.js"
            // Real file path:          C:\MyIde\projects\testProj\source\public\js\someEntryPoint.js

" ?", , . pug sass : .


Update

, Webpack-stream index.js...

function prepareFile (fs, compiler, outname) {
  var path = fs.join(compiler.outputPath, outname);
  if (path.indexOf('?') !== -1) {
    path = path.split('?')[0];
  }

  var contents = fs.readFileSync(path);

  var file = new File({
    base: compiler.outputPath,
    path: nodePath.join(compiler.outputPath, outname),
    contents: contents
  });
  return file;
}
+6

All Articles