npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webpack-shell-plugin-next

v2.3.2

Published

Run shell commands before and after webpack builds

Downloads

222,850

Readme

npm version npm downloads NPM license npm type definitions Build Status donate GitHub Repo stars

Webpack Shell Plugin Next

fix webpack deprecated method. add typescript and other

This plugin allows you to run any shell commands before or after webpack 5 builds. This will work for both webpack 5.

Goes great with running cron jobs, reporting tools, or tests such as selenium, protractor, phantom, ect.

Webpack compatibility

| Webpack | webpack-shell-plugin-next | |:--------|:--------------------------| | -4.x | 1. | | 5.x | 2.* |

WARNING

This plugin is meant for running simple command line executions. It is not meant to be a task management tool.

Installation

npm install --save-dev webpack-shell-plugin-next

Setup

In webpack.config.js:

const WebpackShellPluginNext = require('webpack-shell-plugin-next');
...
module.exports = {
  //...
  plugins: [
    new WebpackShellPluginNext({
      onBuildStart:{
        scripts: ['echo "Webpack Start"'],
        blocking: true,
        parallel: false
      }, 
      onBuildEnd:{
        scripts: ['echo "Webpack End"'],
        blocking: false,
        parallel: true
      }
    })
  ]
  //...
}

More example in webpack.config.ts

API

  • onBeforeBuild: array of scripts to execute before every build.
  • onBuildError: array of scripts to execute when there is an error during compilation.
  • onBuildStart: configuration object for scripts that execute before a compilation.
  • onBuildEnd: configuration object for scripts that execute after files are emitted at the end of the compilation.
  • onBuildExit: configuration object for scripts that execute after webpack's process is complete. Note: this event also fires in webpack --watch when webpack has finished updating the bundle.
  • onWatchRun: configuration object for scripts that execute when webpack's run watch
  • onDoneWatch: configuration object for scripts that execute after files are emitted at the end of the compilation with watch.
  • onBeforeNormalRun: configuration object for scripts that execute on normal run without --watch option
  • onAfterDone: configuration object for scripts that execute after done.
  • onFailedBuild: configuration object for scripts that execute after error.
  • onBeforeCompile: configuration object for scripts that execute before complite.

Default for all: {scripts: [],blocking: false,parallel: false}

  • blocking (onBeforeBuild, onBuildStart, onBuildEnd, onBuildExit, onBuildExit, onWatchRun): block webpack until scripts finish execution.
  • parallel (onBeforeBuild, onBuildStart, onBuildEnd, onBuildExit, onBuildExit, onWatchRun): execute scripts in parallel, otherwise execute scripts in the order in which they are specified in the scripts array.

Note: below combination is not supported.

{
 blocking: true
 parallel: true
} 

Other global params

  • env: Object with environment variables that will be applied to the executables Default: { }
  • logging: show output for internal messages. Default: true
  • swallowError: ignore script errors (useful in watch mode) Default: false
  • dev: switch for development environments. This causes scripts to execute once. Useful for running HMR on webpack-dev-server or webpack watch mode. Default: true
  • safe: switches script execution process from spawn to exec. If running into problems with spawn, turn this setting on. Default: false
new WebpackShellPlugin({
      onBeforeNormalRun: {
        // ...
      },
      dev: false,
      safe: false,
      logging: true
    })
  ]
}

TypeScript

This project is written in TypeScript, and type declarations are included. You can take advantage of this if your project's webpack configuration is also using TypeScript (e.g. webpack.config.ts and webpack.config.js).

Function in scripts

how to use functions in the queue?

Example:

{
  {
    scripts: [
      // sync
      () => {
        console.log('run tTimeout 1');
        setTimeout(() => console.log('end Timeout 1'), 1000);
      },
      // async
      () => new Promise((resolve, reject) => {
        console.log('run async tTimeout');
        setTimeout(() => {
          console.log('end async tTimeout');
          resolve('ok');
        }, 1000);
      }),
    ],
      blocking: true
  }
}
// use exec
import * as os from 'os'
// ..
{
    safe: os.platform() === 'win32', // by default spawn is used everywhere. If you have problems try using safe: true
    scripts: [
      //...
    ]
    //  ...
}

Developing

If opening a pull request, create an issue describing a fix or feature. Have your pull request point to the issue by writing your commits with the issue number in the message.

Make sure you lint your code by running npm run lint and you can build the library by running npm run build.

I appreciate any feed back as well, Thanks for helping!