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)
_
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 = ; moduleexports = ... ... plugins: 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 = ; moduleexports = ... ... plugins: // reference nuget.exe or overwrite nugetPath : path // 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 : consolelog error: consoleerror // custom hook to be able to run the restore at an alternate time instead of compile time // @see Custom runHook method examples below { compilerhookscompile; } hooks: // will call just before the nuget.exe file is executed {} // will call whenever the plugin spits out any output {} // will call whenever there's an issue thrown by the plugin {} // will call when the plugin has successfully completed {} ...
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 = ; moduleexports = ... ... plugins: // the solution path to run nuget restore on solutionPath : 'path/to/solution.sln' { // 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 compilerhookscompilation; } ...
Custom Logger
If you want to stop the plugin logging out to the console, or replace it with your own logger:
const WebpackNugetPlugin = ; moduleexports = ... ... plugins: solutionPath : `path/to/solution.sln` outputConsole: { // 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; } { // 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; } ...
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.