Coder Social home page Coder Social logo

webpack-streaming-task-plugin's Introduction

Webpack Streaming Task Plugin

Execute tasks during Webpack compilation

NPM

Overview

This plugin executes streaming tasks during Webpack compilation, and can be used to easily leverage Gulp plugins while using Webpack.

Installation

Install the plugin with npm:

$ npm install webpack-streaming-task-plugin --save-dev

Or with Yarn:

$ yarn add webpack-streaming-task-plugin --dev

Basic Usage

The example below uses gulp-cssnano and gulp-rename to minify and rename a CSS file that is separate from the main Webpack bundle.

const WebpackStreamingTaskPlugin = require('webpack-streaming-task-plugin');
const cssnano = require('gulp-cssnano');
const rename = require('gulp-rename');

const WebpackConfig = {
  entry: './src/js/index.js',
  output: {
    path: 'dist/js',
    filename: 'index_bundle.js',
  },
  plugins: [
    new WebpackStreamingTaskPlugin({
      name: 'Minify and Rename CSS',
      source: './src/css/stylesheet.css',
      destination: './dist/css',
      task: (task) => {
        return task
          .pipe(cssnano())
          .pipe(rename({
            suffix: '.min',
          }));
      },
    }),
  ]
}

Options

The options object can contain the following properties:

  • source: (String or Array) Glob string or array of glob strings describing task input.
  • destination: (String) Destination path for task output. Set to null to prevent piping output to the filesystem. (Optional, default './')
  • task: (Function) Task function. Includes a task parameter with which to pipe output.
  • name: (String) Name of task, used in log output (Optional)
  • watchMode: (Object) Configuration object for options related to Webpack's watch mode. (Optional)
  • watchMode.includeSourceDirectories: (Boolean) Only applies in watch mode. By default, Webpack only watches for changes to the files specified by source, but directory-level changes (new files, new child directories, etc.) are ignored. When includeSourceDirectories is true, changes to any directories that contain files specified in source will trigger recompilation. (Optional, default false)
  • watchMode.skipInitialRun: (Boolean) Only applies in watch mode. When true, this task is not executed upon Webpack's initial run. Instead, it will only run once changes to its source files are detected. (Optional, default false)
  • watchMode.alwaysRun: (Boolean) Only applies in watch mode. When true, this task is always executed when Webpack runs, even if files specified in source are unchanged. If watchMode.skipInitialRun is also true, skipInitialRun takes priority and the first run will be skipped despite alwaysRun being true. (Optional, default false)
  • watchMode.changedFilesOnly: (Boolean) Only applies in watch mode. When true, only files which have changed since last run will be included in the stream passed to this task. (Optional, default false)

Deprecated Options

The following options should no longer be used and will be removed in future releases. They only exist for legacy compatibility.

  • always: (Boolean) Deprecated. For watch mode only. Serves the same purpose as watchMode.alwaysRun. This option is deprecated. Use watchMode.alwaysRun instead.
  • watchSourceDirectories: (Boolean) Deprecated. For watch mode only. Serves the same purpose as watchMode.includeSourceDirectories. This option is deprecated. Use watchMode.includeSourceDirectories instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.