shama / webpack-stream

:tropical_drink: Run webpack through a stream interface
MIT License
1.39k stars 122 forks source link

the plugin "DefinePlugin" don't work sometimes #157

Open zjruan opened 7 years ago

zjruan commented 7 years ago

Environment

[webpack-stream:3.2.0] [webpack:3.4.1] [node: 7.9.0|8.2.0] [macOS: 10.12.6 ] [windows:10]

Description

my config like this, but the DefinePlugin don't work sometimes.

work

It's so strange, I try to debug, But it's too time-consuming. So, I changed the version of the webpack that the plugin was dependent to 3.4.1, and it was 1.15.x before.

When I have done this, all things are all right.

Therefore, it may be the webpack-stream depends on a too old webpack version.

So I suggest upgrading the dependent webpack version

// demo: 1
var webpack = require('webpack')
var webpackStream = require('webpack-stream');
/**
 * 编译 js 
 */
gulp.task('compile:js:dev', function(){
    return gulp.src(config.src.js)
        .pipe(named(function(file){
            var relativeName = file.relative;
            return relativeName.replace(path.extname(relativeName), '');
        }))
        .pipe(webpackStream({
            externals: {'$': 'window.$'},
            devtool: 'source-map',
            plugins: [
                new webpack.DefinePlugin({
                    STATIC_WEB_PATH: '"//my.test.path"'
                })
            ]
        }))
        .pipe(gulp.dest(config.dist.js))
        .pipe(global.browsersync.stream());
});
// demo: 2
// The final solution of me
gulp.task('compile:js:dev', function(){
    return gulp.src(config.src.js)
        ....
        .pipe(webpackStream({
            externals: {'$': 'window.$'},
            devtool: 'source-map',
            plugins: [
                new webpack.DefinePlugin({
                    STATIC_WEB_PATH: '"//my.test.path"'
                })
            ]
        }, webpack))
        ...
});