I use webpack in my asp.net Core MVC to bundgle js/css files and put it into the wwwroot folder after.
My folder structure looks like this on the screen:
I added "after-build" section into FrontEnd.csproj:
<Target Name="BuildClientAssets" BeforeTargets="Build">
<Exec Command="npm install"/>
<Exec Command="npm run build"/>
</Target>
- FrontEnd/node_modules contains npm modules loaded by "npm install" command;
- Web/wwwroot/dist and Web/wwwroot/fonts contains bundled js/css/fonts files, generated by "npm run build" command;
It works as expected. But it would be great if I had an oppurtunity to exec this command on publish web project.
But when I try to add prepublish section into the Web project and start publish
<Target Name="BuildClientAssets" BeforeTargets="Publish">
<Exec Command="npm install"/>
<Exec Command="npm run build"/>
</Target>
I get this error: The command "npm run build" exited with code -4058
I supposed, that it is because of the package.json located in FrontEnd project (not in the Web project), so I looked for a suitable script to start command in right way and overrrided the section:
<Target Name="BuildClientAssets" BeforeTargets="Publish">
<Exec Command="npm install" />
<Exec Command="webpack --config ../FrontEnd/webpack.config.js" />
</Target>
But after I get errors such as:
Can't resolve './src/components/app/file1.ts' ERROR in Entry module not found 0
Error Can't resolve './src/components/app/file2.ts'
ERROR in Entry module not found 0
Error Can't resolve 'source-map-loader' Module not found 0
The command is started but modules are searched still in the Web, not the FrontEnd project.
Any idea?
