我想为脚本包编写一个自定义转换,它围绕包中的所有文件包装一些JS。我研究了IBundleTransform
接口,我知道我可以像以下任何一个包那样添加一个变换:
public class CustomTransformType : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
string bundleResponse = string.Empty;
foreach (FileInfo file in response.Files)
{
// PROCESS FILE CONTENT
}
response.Content = bundleResponse;
}
}
然而,这使我有责任将所有文件流式传输到一个字符串缓冲区中,然后我可以使用自己的代码进行包装。
我想知道是否有办法获取生成的捆绑文件并使用 THAT 作为我的包装器?所以,做一些像:
public class CustomTransformType : IBundleTransform
{
private string wrapBeg = "(function () {";
private string wrapEnd = "})";
public void Process(BundleContext context, BundleResponse response)
{
string bundleResponse = wrapBeg + response.Bundle + wrapEnd;
}
}
上面的代码说明了我想做什么,而不是实现。
如果以上内容不可用,是否有人可以提出一种流式传输文件的好方法以及我应该注意的一些问题?