I have a aspnet core application with a vue.js part, which I build with webpack and everything works fine.
Now I search a solution to create a productionbuild with it, to create a minified version of my vue bundle and to run vue in production mode (without console.logs), which I set in my webpack.config
like:
if (process.env.NODE_ENV === 'production') {
module.exports.plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
} else {
module.exports.devtool = '#source-map'
}
but process.env.NODE_ENV
is always undefined when I webpack it via gulp.
Than I tried to use Microsoft.AspNetCore.SpaServices
with this line in startup.cs
:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
if(env.IsDevelopment())
app.UseWebpackDevMiddleware();
...
}
This works also fine like my gulp configuration and process.env.NODE_ENV
property is set to 'development'
Now I try to create a production build in VS 2017 (Build -> Publish Projectname), but no webpack task runs.
So i tried to add this in my *.csproj:
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="npm run build" />
</Target>
this throws the error: The command "npm run build" exited with code 1.
Now I'm out of other ideas to resolve it and hope that anyone can help me. THX!
Resolved using:
in .csproj
:
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="npm install" />
<Exec Command="npm run production" />
</Target>
and adding scripts in my package.json
:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack --hide-modules",
"production": "cross-env NODE_ENV=production webpack --hide-modules"
}
this needs webpack
& cross-env
packages (and all other used packages during webpack) installed & a working webpack.config.js
Ask if someone is interrested to my webpack.config.js
or some other code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With