angular - 在 Visual Studio 中以本地生产模式构建 Angular
问题描述
我想在本地测试我的 Angular 应用程序的生产版本(即从dist
文件夹中提供服务),使用 Visual Studio(作为 .net 核心应用程序的一部分)&& IIS Express - 即获得F5
为生产版本提供服务的行为。
我认为这就像添加--prod
到start
(and/or build
) 一样简单,但这不起作用,来自package.json
:
"scripts": {
"ng": "ng",
"start": "ng serve --live-reload false --prod",
"build": "ng build --prod",
"build:ssr": "ng run Website:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
我怎样才能让它正常工作?
解决方案
不完全是F5
,但到目前为止我最接近的是使用 Powershell 脚本:
cls
# build angular in prod to get compiled site (including service worker, etc) in dist folder
Set-Location -Path C:\Users\Sean\Desktop\ngsw\ngsw\ClientApp
ng build --prod
# iis params
$iisExpressExe = '"C:\Program Files\IIS Express\iisexpress.exe"'
$path = "C:\Users\Sean\Desktop\ngsw\ngsw\ClientApp\dist"
Write-host "Starting site on port: 8080"
$params = "/port:8080 /path:$path"
$command = "$iisExpressExe $params"
# open chrome in incognito to avoid cache
[System.Diagnostics.Process]::Start("chrome.exe","--incognito http://localhost:8080/")
# start iis
cmd /c start cmd /k "$command"
Write-Host "Site started"
# sleep a long time...
Start-Sleep -m 1000
推荐阅读
- javascript - 子组件发出自定义事件,但未触发父组件的侦听器
- r - 如何不根据参数执行某些 Rmarkdown 块?
- android - 有没有办法检测屏幕上的压力功率?
- asp.net-core - 如何将 HTML(View) 表数据传递给控制器以保存在 slq 表中
- python - 使用 Python 解码 protobuf 文件时出现一些错误,错误为 'google.protobuf.message.DecodeError: Too many bytes when encrypted varint.'
- java - 小数指数和负基数的数学修正 pow 函数
- c# - 调整窗口大小时如何使 Unity Game 适合任何分辨率?
- jquery - 为什么这两个 Highcharts 调用会产生不同的风玫瑰图
- bash - 粘贴 bash 命令,但确保它没有运行
- javascript - 使用精细上传器将多个文件直接上传到 Laravel 中的 S3