正如 Vladimir 所说,您可以创建自己的 Bundle 转换,只需实现IBundleTransform
. 我写了一篇关于捆绑和缩小 Coffeescripts 的博客文章,可以为您指明正确的方向:http ://tallmaris.com/advanced-bundling-and-minification-of-coffeescripts-in-mvc4/
总之,创建一个像这样的自定义转换:
public class MultiLanguageBundler : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
foreach (var file in response.Files)
{
using (var reader = new StreamReader(file.FullName))
{
// "ReplaceLanguageStrings" contains the search/replace logic
compiled += ReplaceLanguageStrings(reader.ReadToEnd());
reader.Close();
}
}
response.Content = compiled;
response.ContentType = "text/javascript";
}
}
然后在你的BundleConfig
:
var myBundle = new Bundle("~/Scripts/localised")
.Include("~/JsToLocalise/*.js"); //your JS location here, or include one by one if order is important.
myBundle.Transforms.Add(new MultiLanguageBundler());
myBundle.Transforms.Add(new JsMinify());
bundles.Add(myBundle);
您可能需要调整一些东西,但如果它对您有帮助,请告诉我。