问题
I want to reproduce this Gulp script with webpack to have only one process who listen on files but i can't make it work. This is my Gulp task
gulp.task('scripts', function(){
return gulp.src( WATCH_SCRIPTS.SCRIPTS )
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat('plugins.min.js'))
.pipe(babel({ compact: false, babelrc: false, presets: ['es2015-allow-top-level-this'] }))
.pipe(ifElse(PROD_ENV,
() => {return uglify({
hoist_vars: true,
global_defs: {
jQuery: false,
$: false,
}
})},
() => {return sourcemaps.write('./')}
))
.pipe(plumber.stop())
.pipe(gulp.dest(BUILD_PATH + '/js'));
});
I tried with the expose-loader, but it always misses some dependancies.
{
name: 'scripts',
target: 'web',
entry: glob.sync('./src/assets/js/**/*.js'),
devtool: 'cheap-module-eval-source-map',
output: {
path: path.resolve(__dirname, 'public/js/'),
filename: 'plugins.min.js',
sourceMapFilename: 'plugins.min.js.map',
},
module: {
rules: [
{
test: /[\/]global\.js$/,
use: [{
loader: 'expose-loader',
options: 'Materialize'
}]
},
{
test: /[\/]jquery\.js$/,
use: [{
loader: 'expose-loader',
options: 'jQuery'
},{
loader: 'expose-loader',
options: '$'
}]
}
]
}
}
I tried with the babel-loader with the preset (like in the gulp task)
presets: ['es2015-allow-top-level-this']
Materialize was undefined from this file https://github.com/Dogfalo/materialize/blob/master/js/global.js.
Can i just listen to files changes and start my gulp scripts
or is there a way to concatenate files directly? I'm very new to webpack 2.
Thank you
回答1:
Try 'script-loader' It does not concatenate, but it executes the script in the global context, which is what I originally needed when looking for "simple concatenation".
来源:https://stackoverflow.com/questions/43879823/trying-to-concatenate-js-files-with-webpack-like-a-gulp-script