Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 8, 2019. It is now read-only.
/docsPublic archive

usage with gulp

Zearin edited this pageSep 5, 2016 ·20 revisions

Using webpack with gulp is as easy as using thenode.js API.

vargulp=require('gulp');varwebpack=require('webpack-stream');gulp.task('default',function(){returngulp.src('src/entry.js').pipe(webpack()).pipe(gulp.dest('dist/'));});

The above will compilesrc/entry.js into assets with webpack intodist/ with the output filename of«hash».js (a webpack-generated hash of the build).

Or just pass in yourwebpack.config.js:

returngulp.src('src/entry.js').pipe(webpack(require('./webpack.config.js'))).pipe(gulp.dest('dist/'));

Seewebpack-stream for more options and details.

Withoutwebpack-stream

vargulp=require("gulp");vargutil=require("gulp-util");varwebpack=require("webpack");varWebpackDevServer=require("webpack-dev-server");

Normal compilation

gulp.task("webpack",function(callback){// run webpackwebpack({// configuration},function(err,stats){if(err)thrownewgutil.PluginError("webpack",err);gutil.log("[webpack]",stats.toString({// output options}));callback();});});

Don't be too lazy to integrate thewebpack-dev-server into your development process. It's an important tool for productivity.

gulp.task("webpack-dev-server",function(callback){// Start a webpack-dev-servervarcompiler=webpack({// configuration});newWebpackDevServer(compiler,{// server and middleware options}).listen(8080,"localhost",function(err){if(err)thrownewgutil.PluginError("webpack-dev-server",err);// Server listeninggutil.log("[webpack-dev-server]","http://localhost:8080/webpack-dev-server/index.html");// keep the server alive or continue?// callback();});});

Example

Take a look at an example gulpfile. It covers three modes:

  • webpack-dev-server
  • build - watch cycle
  • production build

Example gulpfile

webpack 👍

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp