0

.NET MVC 5 응용 프로그램에서 웹 최적화 프레임 워크의 번들 및 축소 기능을 사용하고 있습니다.번들 및 축소 - 스크립트가 디버그 모드에서 참조되지 않습니다.

BundleConfig.cs 다음 _Layout.cshtml 파일에서

public static void RegisterBundles(BundleCollection bundles) 
    { 

     bundles.Add(new ScriptBundle("~/bundles/home").Include(
        "~/Scripts/jquery-1.11.0.min.js", 
        "~/Scripts/bootstrap.min.js", 
        "~/Scripts/owl.carousel.min.js", 
        "~/Scripts/wow.min.js", 
        "~/Scripts/front.js")); 

    } 

이 같은 번들을 참조하고 있습니다 :

@Scripts.Render("~/bundles/home") 

이 모두 서버에서 예외없이, 릴리스 모드, 즉 debug = false에서 작동 & 클라이언트 측.

그러나 디버그를 true로 설정하면 front.js을 제외한 모든 스크립트가 페이지에서 참조됩니다.

나는 Application_Start() 이벤트에이 추가 시도하지만 난 여전히 같은 문제가 발생 : 당신은에서 스크립트 참조를 변경해야

<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0"/> 
    <add key="webpages:Enabled" value="false"/> 
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
    </appSettings> 
    <system.web> 
    <compilation debug="false" targetFramework="4.5.2"/> 
    <httpRuntime targetFramework="4.5.2"/> 
    <caching> 
     <outputCacheSettings> 
     <outputCacheProfiles> 
      <add name="Cache1Week" duration="604800" varyByParam="none"/> 
     </outputCacheProfiles> 
     </outputCacheSettings> 
    </caching> 
    </system.web> 
    <system.net> 
    <mailSettings> 
     <smtp from="[email protected]"> 
     <network host="localhost" port="25"/> 
     </smtp> 
    </mailSettings> 
    </system.net> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral"/> 
     <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0"/> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" culture="neutral"/> 
     <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0"/> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/> 
    </compilers> 
    </system.codedom> 

</configuration> 
+0

Application_Start()가 아닌 RegisterBundles에 if 논리를 포함하십시오. –

+0

BundleConfig에 넣으려고합니까? 그렇다면 차이는 없습니다. – Esen

답변

1

:

여기
#if DEBUG 
      BundleTable.EnableOptimizations = false; 
#else 
      BundleTable.EnableOptimizations = true; 
#endif 

Web.config 파일

"~/Scripts/something.min.js", 

to :

"~/Scripts/something.js", 

debug가 들러가 자동으로 (컨벤션 something.min.js 사용) 축소 된 파일을 찾을 것 false입니다. 그렇지 않으면 나열된 파일을 사용합니다.

항상 bundler를 압축되지 않은 파일로 지정하십시오. minifier가 이것을 처리 할 수는 있지만 축소 된 사본을 가리키면 축소를 실행 취소 할 수는 없습니다.

+0

고맙습니다! 나는 단지 파일에서'min' 부분을 제거했기 때문에 컨벤션은 파일 이름 만보고 내용이 아니라는 것을 믿습니다. – Esen

+0

맞습니다. 이 규칙은 파일 이름과'.min.js'가 이미 포함되어 있는지 여부에만 적용됩니다. – Amy