So I have a Gulp file (working) and a Webpack file (working). Now I want to combine these to so that I only have to run webpack in order to watch and compile SCSS files.
Looking at webpack home page I can use something called webpack-stream
var gulp = require('gulp'); var webpack = require('webpack-stream'); gulp.task('default', function() { return gulp.src('src/entry.js') .pipe(webpack()) .pipe(gulp.dest('dist/')); }); I don't understand what I'm reading here. And I'm not to familier with piping.
- The first piece of code, does this go into gulpfile.js?
- What is entry.js?
- What does this piece of code do?
The above will compile src/entry.js into assets with webpack into dist/ with the output filename of [hash].js (webpack generated hash of the build).
Or just pass in your webpack.config.js:
return gulp.src('src/entry.js') .pipe(webpack( require('./webpack.config.js') )) .pipe(gulp.dest('dist/')); I'm guessing this goes into my gulpfile.js?
I think I need this handed to me with a tea spoon :-/
Update
I got it working with help from @kannix and @JMM. Here are my config files:
Gulp
var gulp = require('gulp'); var sass = require('gulp-sass'); var webpack = require('webpack-stream'); gulp.task('default', [ 'webpacker', 'sass', 'watch' ]); gulp.task('webpacker', function() { return gulp.src('./src/index.js') .pipe(webpack(require('./webpack.config.js'))) .pipe(gulp.dest('dist/')); }); gulp.task('sass', function () { return gulp .src('./src/sass/main.scss') .pipe(sass()) .pipe(gulp.dest('./css/')); }); gulp.task('watch', function() { gulp.watch('./src/sass/*.scss', ['sass']); gulp.watch('./src/components/*.jsx', ['webpacker']); }); webpack.config.js
var path = require('path'); var webpack = require('webpack'); module.exports = { entry: "./src/index.js", output: { path: __dirname + "/js/", filename: "bundle.js" }, module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel', query: { cacheDirectory: true, presets: ['es2015', 'react'] } } ] } };