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-nuget-plugin

v1.0.3

Published

A webpack plugin to run nuget commands during compilation time.

Downloads

9

Readme

npm version npm

Webpack Nuget Plugin

This plugin allows you to run nuget restore at a specific times using the Webpack compilation hooks. This plugin is shipped with the Nuget.exe (v3.4.4.1321)so we don't have to automatically locate it, however you can also point to a different one using the configuration options.

This plugin was built for Windows 10 and Windows Server 2012 - it is not tested in any other OS and most likely will have issues. Written in Node v9 for webpack 4, webpack 3 won't work as they've changed the hook functionality (can work with very little work)

  1. Installation
  2. Setup Basic
  3. Setup Advanced
  4. Custom Run Hook
  5. Custom Logger

_

Installation

npm install webpack-nuget-plugin

Setup Basic

Simplest configuration a nuget commands which will run when webpack has finished compilation will happen by using the runHook, (you can also change when the runHook method) In webpack.config.js:

By default it will run in 'restore' mode, you can change this by using the args configuration options:

const WebpackNugetPlugin = require('webpack-nuget-plugin');

module.exports = {
    ...
    ...
    plugins: [
        new WebpackNugetPlugin({
            solutionPath: 'path/to/project.sln'
        })
    ],
    ...
}

Setup Advanced

Extended functionality/configuration and all their defaults, this outlines the possiblity with hooks, console, runHook and the other options that are possible for this plugin.

const WebpackNugetPlugin = require('webpack-nuget-plugin');

module.exports = {
    ...
    ...
    plugins: [
        new WebpackNugetPlugin({
            // reference nuget.exe or overwrite
            nugetPath : path.resolve(__dirname, './nuget.exe'),
            // the solution path to run nuget restore on
            solutionPath : undefined,
            // can use mono if needed (will only use this if it's provided)
            monoPath: null,
            // default arguments
            args : ['restore'],
            // can pass additional arguments to the nuget exe as it's executed
            // http://docs.nuget.org/docs/reference/command-line-reference
            additionalArgs: [],
            // custom callbacks to the output console
			outputConsole : {
				log : console.log,
				error: console.error
            },
            // custom hook to be able to run the restore at an alternate time instead of compile time
            // @see Custom runHook method examples below
			runHook(compiler, run) {
				compiler.hooks.compile.tap('WebpackNuget', run);
            },
            hooks: {
                // will call just before the nuget.exe file is executed
                onStart: (data) => {},
                // will call whenever the plugin spits out any output
                onData: (data) => {},
                // will call whenever there's an issue thrown by the plugin
                onError: (data) => {},
                // will call when the plugin has successfully completed
                onDone: (data) => {}
            }
        })
    ],
    ...
}

Custom Run Hook

By default this plugin will run before a new compilation is created, there's a wide range of hooks available from Webpack, By default we use 'compile'.

const WebpackNugetPlugin = require('webpack-nuget-plugin');

module.exports = {
    ...
    ...
    plugins: [
        new WebpackNugetPlugin({
            // the solution path to run nuget restore on
            solutionPath : 'path/to/solution.sln',
			runHook(compiler, run) {
                // compiler.hooks.compile.tap('WebpackNuget', run);
                // instead of running before compilition, now we're running after compilation
                // just make sure you understand the tap libarary the webpack's core hook functionality
                // is build from: https://github.com/webpack/tapable
                compiler.hooks.compilation.tap('WebpackNuget', run);
            }
        })
    ],
    ...
}

Custom Logger

If you want to stop the plugin logging out to the console, or replace it with your own logger:

const WebpackNugetPlugin = require('webpack-nuget-plugin');

module.exports = {
    ...
    ...
    plugins: [
        new WebpackNugetPlugin({
            solutionPath : `path/to/solution.sln`,
            outputConsole: {
                log(data) {
                    // data is an object, containing a type, msg and extra data like what project is sending the output, 
                    // or where abouts in the chain is it throwing the output
                    console.log(data.msg);
                },
                error(data) {
                    // data is an object, containing a type, msg and extra data like what project is sending the output, 
                    // or where abouts in the chain is it throwing the output
                    process.exit(0);
                }
            }
        })
    ],
  ...
}

Development

If you want to contribute or extend this plugin, clone the repository and run npm install, then there's only two scripts: npm run build, npm run watch. There's no tests (yet), make your changes in src and the output lib will update.