admin管理员组文章数量:1388105
I'm using Asp Core +Angular 4 template + webpack in VS 2017. I've published my app ..and looking to ClientApp/dist/main-server.js I see the content is not uglify and minify..it is something like this
...
ConfirmComponent.prototype.ngAfterViewInit = function () {
try {
$('.modal').removeClass('fade');
setTimeout(function () {
$('.modal').addClass('fade');
}, 500);
}
catch (exception) { }
};
...
in webpack.config.vendor.js I can see a plugin call:
....
plugins: [
extractCSS,
new webpack.DllPlugin({
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
name: '[name]_[hash]'
})
].concat(isDevBuild ? [] : [
new webpack.optimize.UglifyJsPlugin() //HERE
])
});
....
in package.json I've added: "uglifyjs-webpack-plugin": "1.0.1",
how to uglify and minify the code?
thanks
I'm using Asp Core +Angular 4 template + webpack in VS 2017. I've published my app ..and looking to ClientApp/dist/main-server.js I see the content is not uglify and minify..it is something like this
...
ConfirmComponent.prototype.ngAfterViewInit = function () {
try {
$('.modal').removeClass('fade');
setTimeout(function () {
$('.modal').addClass('fade');
}, 500);
}
catch (exception) { }
};
...
in webpack.config.vendor.js I can see a plugin call:
....
plugins: [
extractCSS,
new webpack.DllPlugin({
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
name: '[name]_[hash]'
})
].concat(isDevBuild ? [] : [
new webpack.optimize.UglifyJsPlugin() //HERE
])
});
....
in package.json I've added: "uglifyjs-webpack-plugin": "1.0.1",
how to uglify and minify the code?
thanks
1 Answer
Reset to default 4I remend refactoring your code to work with the Angular CLI, and then minifying with:
ng build --prod
With a Web API project on core, once you create a new Angular App with (run this from the same directory as your solution (sln) file:
ng new my-app
Then:
- In angular-cli.json, change outDir to wwwroot
- In tsconfig.json, change outDir to ./wwwroot/out-tsc
At this point, ng build will publish everything to wwwroot, so as long as you include:
app.UseDefaultFiles();
In the Configure method in Startup.cs, browsing to the root of your API will display your Angular app.
Additionally, I like to include a proxy file, called proxy.config.json, which looks like this (replace the port with your API port):
{
"/api/*": {
"target": "http://localhost:12345",
"secure": false,
"logLevel": "debug"
}
}
Then, I amend the start script in package.json, like so:
"start": "ng serve --proxy-config proxy.config.json"
At this point, you can debug your API, and just run npm start from the mand line, making full use of the Angular CLI. Then, when you want to release, run:
ng build --prod
Also, you can amend your .csproj file to build and minify your angular app when you build your Web API project like so:
<Target Name="Build Angular" BeforeTargets="Build">
<Message Text="* * * * * * Building Angular App * * * * * *" Importance="high" />
<Exec Command="ng build --prod" />
</Target>
I personally view Angular as an all-in framework. I don't see the value of using it with Razor. If you want progressive enhancement, use React!
本文标签: javascriptUglify and minify Angular 4 codeStack Overflow
版权声明:本文标题:javascript - Uglify and minify Angular 4 code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744566144a2613059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论