Reputation: 347
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>
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?
Upvotes: 3
Views: 1281
Reputation: 387
The npm install
isn't hitting the right folder either, you need run these commands inside the right location - probably worked in your machine because it already have the node-modules. You can keep both commands (ǹpm install
/ npm run build
) and try to target the right location. How you can do that? You could inform the command the folder he will run.
First, set in the PropertyGroup
section the front-end folder location
<FrontRoot>../FrontEnd/</FrontRoot>
and pass the property in the command lines using the WorkingDirectory
property. It will looks like this:
<Target Name="BuildClientAssets" BeforeTargets="Publish">
<Exec WorkingDirectory="$(FrontRoot)" Command="npm install"/>
<Exec WorkingDirectory="$(FrontRoot)" Command="npm run build"/>
</Target>
There is a similar situation here
Upvotes: 2