2013-10-03 18 views
1

使用grunt時,可以更改html文件中的引用。Grunt change index.html參考

例如,作爲我的構建過程的一部分,我將文件名從style.css更改爲style.min.css。

我想要做的是在我的index.html文件中改變對使用縮小版本的樣式表的引用。

回答

0

另一種可能的解決方案,從而避免了在你的HTML標記定義塊的評論,是安裝一個名爲插件:

$ npm install grunt-text-replace --save-devgrunt-text-replace

通過NPM安裝插件

然後將以下內容添加到您的Gruntfile

Gruntfile.js:

grunt.initConfig({ 

    pkg: grunt.file.readJSON('package.json'), 

    /* UPDATES CSS SRC REFERENCED IN YOUR THE HTML FILE */ 
    replace: { 
     cssLink: { 
      src: ['./src/index.html'], //<--- The path to your html file 
      overwrite: true, 
      replacements: [{ 
       // Subsitute src="css/ below with the path to your CSS file. 
       from: 'src="css/style.css', 
       // Subsitute src="css/ above with the path to your minified CSS file. 
       to: 'src="css/style.min.css' 
      }] 
     } 
    } 

}); 

grunt.loadNpmTasks('grunt-text-replace'); 

grunt.registerTask('default', [ 
    'replace:cssLink' 
]); 

};