如何配置 ASP.NET 核心静态文件以根据环境(prod vs dev)更改?

How to configure ASP.NET Core static files to change based on Environments (prod vs dev)?

我有一个 ang2,VS 2015,ASP.NET 4.6.1 项目正在进行,但它是一个非 mvc。所以我无法访问 <environment>。也使用 gulp,以便可以将其用作解决方案的一部分。

如何配置静态文件,例如 index.html 以使用缩小版本的文件?目前我正在使用 gulp 来完成这项工作。

我看过这个,但它是针对 MVC 项目的。 https://docs.asp.net/en/latest/fundamentals/environments.html

更新:

示例:

如何让 wooroot 文件夹中的 Index.html 指向开发中的非缩小脚本,然后指向生产中的缩小版本?就像url中的例子一样。使用 MVC 时,您可以让它换出代码。如果没有 MVC,这似乎是不可能的。

您可以通过使用自定义选项调用 app.UseStaticFiles 来更改静态文件的位置。

if (env.IsDevelopment())
{
    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
        RequestPath = new PathString("/StaticFiles")
    });
}

请注意,可能存在多个 app.UseStaticFiles 调用。有关详细信息,请参阅 Working with Static Files 文档。

好的,找到了我要找的答案。

使用gulp-html-替换,https://www.npmjs.com/package/gulp-html-replace

<!-- build:<name> -->
Everything here will be replaced
<!-- endbuild -->

示例:

index.html

<!-- build:css -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<!-- endbuild -->

</head>
<body>

<!-- build:js -->
<script src="js/player.js"></script> 
<script src="js/monster.js"></script> 
<script src="js/world.js"></script> 
<!-- endbuild -->

gulpfile.js

var gulp = require('gulp');
var htmlreplace = require('gulp-html-replace');

gulp.task('default', function() {
  gulp.src('index.html')
    .pipe(htmlreplace({
        'css': 'styles.min.css',
        'js': 'js/bundle.min.js'
    }))
    .pipe(gulp.dest('build/'));
});