If you are still uncertain about Front-end dev, you can take a quick look into an excellent resource here. gulp.Repost my killer answer on stackoverflow with more than 600 votes. Here's what the updated Gulp task would look like. There's also the option of skipping webpack-stream completely if that's your preference. What's changed here is that now the webpack module is being required in the gulpfile.js, and the webpack task had been updated to use that included package. Return webpack_stream(webpack_config, webpack) One interesting feature of the webpack-stream plugin is that if you wanted to use a different version of Webpack than what the package depends on, you can require and pass that version along in an optional 2nd parameter. Now we should be able to kick off a build by just running gulp on in the terminal. If you're following along from the previous post and have your precompile script set to call webpack, you can now change that to or just since that's the default task. For instance, you may want to invoke Typings as a pre-step to restore your *.d.ts definition files. You may continue to add other build steps to compose your pipeline the way you want it. On the rare occasion that you rename or remove bundles, it's good to have a clean space for your final output. This makes sure that the destination folder is empty before running your build. Also notice that the webpack task relies on the clean task to be run first. In the webpack task we're simply passing the exported config from and handing it over to webpack-stream. It comes in handy when diagnosing build issues. The gulp-print package is optional, but I find it useful to print out what files are getting piped around. In the clean task, we're taking a stream of all the files from the /del isn't stream based, so the vinyl-paths package is used to get the file paths out of the stream and pass them into del. There are only 2 gulp tasks defined clean and webpack. I'm keeping this gulpfile.js file fairly minimal for the sake of the post. const gulp = require('gulp') Ĭonst vinylPaths = require('vinyl-paths') Ĭonst webpack_stream = require('webpack-stream')Ĭonst webpack_config = require('./') If you don't have one already just create an empty file in your project root. Next, let's add the Gulp task to the gulpfile.js file in your project.
WHY USE WEBPACK VS GULP INSTALL
npm install webpack-stream gulp-print gulp-util del vinyl-paths -save-dev Go ahead and grab it from NPM along with a few other packages that we'll make use of. This package will allow Webpack to be run in a stream which is what we need. To plug Webpack into a Gulp task we're going to use the webpack-stream package. Make sure your command terminal is located at your project root. Running the following commands will take care of that for you. Let greeting: string = greeter.getGreeting() īased on the Gulp documentation, its recommended to install the gulp-cli globally in addition to installing a local version of Gulp as a devDependency in your package.json file.
Let greeter : Greeter = new Greeter('Cecil') As a quick catch up, here's what the and *.ts files look like. I'm going to build off the TypeScript project that was created in a previous post.
Now if you have Gulp already setup then you can skip this section.
WHY USE WEBPACK VS GULP HOW TO
In this post, we'll see how to have Gulp use Webpack for bundling. Actually, I have gulp tasks in a file that I tend to just copy what I need from it into new projects and tweak accordingly. If you're like me, you may already have made an investment in adding Gulp to many of your new and existing projects. Depending on the tool you use to scaffold your web project, you may already have support for Gulp ready to go. It has an solid community that's continuing to add new features and plugins to make setting up your build pipeline easier. Gulp has been a popular task automation toolkit in the frontend web development space for some time now.