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 🙏

© 2025 – Pkg Stats / Ryan Hefner

prescript-webpack-plugin

v0.2.0

Published

Webpack plugin for running scripts before build

Readme

prescript-webpack-plugin

Prescript is intended for those rare cases where you want to run scripts before transpiling/bundling your code with webpack.

A typical example usage is to auto-generate e.g typescript typings based on often changing json files like language files. On every run of webpack the scripts will be run before any transpiling or bundling takes place.

Installing

npm install prescript-webpack-plugin

Usage

const PrescriptWebpackPlugin = require('prescript-webpack-plugin');

Add the plugin to your webpack plugins section:

plugins: [
    new PrescriptWebpackPlugin({
        // Scripts are executed in the order they are added
        // The different types of scripts are listed further down in the documentation
        scripts: [
            {
                type: 'node',
                args: ['arg1'],
                scriptFile: path.join(__dirname, 'prescript.js')
            },
            {
                type: 'node',
                args: [1, 'param2'],
                script: (param1, param2) => {
                    console.log(param1, param2);
                }
            }
        ]
    })
];

Prescript types

node

Node scripts are plain javascript that can be executed either as an inline script or as a separate process using a .js file as input.

| Property | Description | | ---------------- | ------------------------------------------------------------------------------------ | | type | Must be set to 'node' | | interpreter | Optional. Specify an alternative node executable if required when using scriptFile | | scriptFile | Absolute path to script file that should be run, can't be combined with script | | script | A function that should be run, can't be combined with scriptFile | | args | Optional. Must be strings when using scriptFile | | throwOnError | If a build should fail on an error or continue silently | | workingDirectory | The working directory used when executing scriptFile, defaults to webpack's |

Examples

Using scriptFile:

{
    type: 'node',
    args: ['arg1'],
    scriptFile: path.join(__dirname, 'prescript.js'),
    interpreter: '/some/path/to/node',
    workingDirectory: '/work/dir/for/node',
    throwOnError: true
}

Using script:

{
    type: 'node',
    args: [1, 'param2'],
    script: (param1, param2) => {
        console.log(param1, param2);
    }
}

ts-node

Similar to type: 'node' but executes a script file using ts-node instead which allows you to use TypeScript.

| Property | Description | | ---------------- | ----------------------------------------------------------------------------- | | type | Must be set to 'ts-node' | | interpreter | Optional. Specify an alternative ts-node executable if required | | args | Optional. Must be strings | | throwOnError | If a build should fail on an error or continue silently | | workingDirectory | The working directory used when executing scriptFile, defaults to webpack's |

Examples

Using scriptFile:

{
    type: 'ts-node',
    args: ['arg1'],
    scriptFile: path.join(__dirname, 'prescript.ts'),
    interpreter: '/some/path/to/ts-node',
    workingDirectory: '/work/dir/for/ts-node',
    throwOnError: true
},

shell

Run any shell command, this could for example enable you to run python scripts or anything else that could be needed.

| Property | Description | | ---------------- | -------------------------------------------------------------------------- | | type | Must be set to 'shell' | | command | The shell command you want to execute | | args | Optional. Must be strings | | throwOnError | If a build should fail on an error or continue silently | | workingDirectory | The working directory used when executing command, defaults to webpack's |

Examples

{
    type: 'shell',
    command: 'echo',
    args: ['hello', 'world'],
    workingDirectory: '/work/dir/for/command',
    throwOnError: true
},

Common issues

Since prescripts are executed just before webpack's build triggers it can cause issues when modifying files that webpack works with during building in combination with webpack's watchers. To accomodate this, you can tweak the amount milliseconds that need to elapse before executing prescripts again.

plugins: [
    new PrescriptWebpackPlugin({
        millisecondsBetweenRuns: 500, // 500 ms is the default
        scripts: [
            /* ... */
        ]
    })
];