Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What webpack-stream doing with file object? #169

Open
ghost opened this issue Nov 9, 2017 · 0 comments
Open

What webpack-stream doing with file object? #169

ghost opened this issue Nov 9, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 9, 2017

Thank you for the amazing package. Thanks to you, I don't need webpack.config.js and separate webpack launch anymore.

In the following experiment, I explored than gulp-webpack doing something with file object:

const webpackStream = require('webpack-stream'),
    webpack = webpackStream.webpack,
    named = require('vinyl-named'),
    path = require('path');

const ES6_SOURCE_FILES_GLOB_SELECTOR = [
    'development/source/public/js/**/*.js',
    'development/source/admin/js/**/*.js',
];

// without gulp-webpack:
return gulp.src(ES6_SOURCE_FILES_GLOB_SELECTOR)
    //.pipe(named())
    //.pipe(webpackStream(options))
       .pipe(gulp.dest( file => {
        
        console.log('dirname: '+file.dirname);
        // dirname: C:\MyIDE\projects\testProject\development\admin\js
    
// ... and with it:
 return gulp.src(ES6_SOURCE_FILES_GLOB_SELECTOR)
      //.pipe(named())
      .pipe(webpackStream(options))
      .pipe(gulp.dest( file => {
        
      console.log('dirname: '+file.dirname);
      // dirname: C:\MyIDE\projects\testProject

I need to define the conditional output in gulp.dest. To do it, I need to know full source path of every file. Here how I do it for SASS task and how I want to do same thing for webpack:

const SASS_SOURCE_FILES_SELECTOR = [
    'development/source/public/sass/**/*.sass',
    'development/source/admin/sass/**/*.sass'],

	PUBLIC_FOLDER_NAME = 'public', 
    ADMIN_FOLDER_NAME = 'admin'; 

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

    return gulp.src(SASS_SOURCE_FILES_SELECTOR)
        .pipe(sass())
        .pipe(gulp.dest( file => {
        
        	let pathSegments = file.dirname.split(path.sep);
            let pathSegmentsCount = pathSegments.length;
       
            for (let i = pathSegmentsCount - 1; i > 0; i--) {
                
                switch (pathSegments[i]) {
                    case PUBLIC_FOLDER_NAME: {
                        return `${file.cwd}\\development\\devBuild\\${PUBLIC_FOLDER_NAME}\\js`;
                    }
                    case ADMIN_FOLDER_NAME: {
                        return `${file.cwd}\\development\\devBuild\\${ADMIN_FOLDER_NAME}\\js`;
                    }
                    default:{
                        break;
                    }
                }
            }
    }));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants