2015-01-12 30 views
2

鑑於以下文件app.js如何更換鏈接版本UI路由器的文件與usemin

$stateProvider 
     .state('intro', { 
     url: '/intro', 
     templateUrl: 'partials/intro.html', 
     controller: 'IntroController as IntroCtrl' 
     }) 
     .state('search', { 
     url: '/search', 
     templateUrl: 'partials/search.html', 
     controller: 'SearchController as searchCtrl' 
     }) 
     ; 

的任務是將templateUrl文件改變向其中revisioned與grunt filerev他們revisioned同行。

我有一個usemin目標與咕嚕

useminPrepare: {// configuration which tasks usemin will change/run 
     html: build_src + '/index.html',    
     options: { 
      dest: build_dest + '', 
     } 
},  
usemin: {   
    html: [build_dest + '/index.html'],    
    options: { 
      dirs: [build_dest + '', build_dest + '/dist']   
    }  
} 

據記載如何插入HTML中塊註釋,然後usemin執行revisioning並更換revisioned文件。

javascript文件是如何實現的?

回答

5

我繼續cetia的答案

我找到了解決方案後,搜索: https://github.com/yeoman/grunt-usemin/issues/235#issuecomment-33316221

usemin: { 
      html: [build_dest + '/index.html'], 
      js:[build_dest + '/**/*.js'], 
      options: { 
       dirs:[build_dest, build_dest + '/dist'], 
       assetsDirs: [build_dest], 
       patterns: { 
         // FIXME While usemin won't have full support for revved files we have to put all references manually here 
         js: [ 
          [/(partials\/.*?\.html)/gm, 'Update the JS to reference our revved partials'] 
         ] 
       } 
      } 
     } 

重要的補充是模式。你需要對usemin說如何在javascript中搜索html鏈接。

assetDirs選項對於設置也很重要,因爲usemins fileprocessor.js會通過未複製文件到revved文件的映射來查找rev文件,並且如果assetDirs設置不正確,它將無法找到它。

1

您需要告訴usemin以替換JS文件中的「filerev」映射。

嘗試增加在usemin配置了 「JS」 的一部分:

usemin: {   
    html: [build_dest + '/index.html'], 
    js: ['js/**/*.js']  
    options: { 
      dirs: [build_dest + '', build_dest + '/dist']   
    }  
} 

此外,你也可以Concat的所有HTML文件只有一個大的(與咕嚕-html2js)採用了棱角分明$ cacheTemplate

+0

我補充瞭解決方案和其他選項,我不得不設置 –

+1

做得好。很高興你的錯誤得到解決。你現在可以接受你自己的答案:p –

相關問題