Azure DevOps - how to build bundles using webpack during deployment
According to Microsoft's documentation, it seems that a "webpack" command in the script
section of your YAML pipeline should do the trick:
- script: webpack
The condition is: "To have this work, make sure that webpack is configured as a development dependency in your package.json
project file. This will run webpack with the default configuration unless you have a webpack.config.js
file in the root folder of your project."
They also mention you need to do this after your compilation and tests. There's a suggestion that you can move this logic out of the pipeline and into your code by using script objects in package.json:
- script: npm run build
Source: Microsoft docs
EDIT: The way I've done it is the with the 2nd recommendation. I have this in my MVC ASP.NET project file:
<Target Name="AfterBuild"> <Exec Condition="$(Configuration) == 'Debug'" Command="npm run build-dev" /> <Exec Condition="$(Configuration) == 'Release'" Command="npm run build-prod"/></Target>
and build-prod for example is just a script in the webpack.config.js:
"build-prod": "SET NODE_ENV=production && webpack -p --color"
build-dev has the -d
argument instead but that's all...