Can the Bundle.config include ScriptBundles?

旧街凉风 提交于 2019-12-12 12:29:48

问题


Can I include scripts in my Bundle.config file, or is it only for style bundles?

<?xml version="1.0" encoding="utf-8" ?>
<bundles version="1.0">
  <styleBundle path="~/Content/css">
    ...
  </styleBundle>
  <scriptBundle path="~/Scripts">

    Is this possible?

  </scriptBundle>
</bundles>

Also can anyone provide a link to a Bundle.config reference that explains the possible tags and structure? I've searched but all I can come up with is the BundleConfig.cs code way of bundling rather than the markup. I realise why - the markup way is older and maybe even deprecated. But I would like to learn the markup way as its common I will be working with legacy systems that use the older method.


回答1:


This is called a "bundle manifest". This is an XML file located at ~/bundle.config and loaded through BundleManifest.ReadBundleManifest(); in your Application_Start.

There is an XSD in CodePlex, named BundleManifestSchema.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="BundleConfig" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="include">
    <xs:attribute name="path" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name="styleBundle">
    <xs:sequence>
      <xs:element name="include" type="include" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="path" type="xs:string" use="required" />
    <xs:attribute name="cdnPath" type="xs:string" use="optional" />
  </xs:complexType>

  <xs:complexType name="scriptBundle">
    <xs:sequence>
      <xs:element name="include" type="include" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="path" type="xs:string" use="required" />
    <xs:attribute name="cdnPath" type="xs:string" use="optional" />
    <xs:attribute name="cdnFallbackExpression" type="xs:string" use="optional" />
  </xs:complexType>

  <xs:element name="bundles">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element type="styleBundle" name="styleBundle" />
        <xs:element type="scriptBundle" name="scriptBundle" />
      </xs:choice>
      <xs:attribute name="version" type="xs:string" />
    </xs:complexType>
  </xs:element>

</xs:schema>

So yes, scriptBundle is supported.




回答2:


I don't think it's possible and I think you should really avoid using the XML notation. There are almost no resources regarding that topic on the web. So it might be faster to just rewrite the XML to C#. However, there is a NuGet package that will allow you to configure it via XML. The example can be found on GitHub and on the project site.



来源:https://stackoverflow.com/questions/31364077/can-the-bundle-config-include-scriptbundles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!