Grunt的wiredep任務的配置說明文檔,gruntwiredep
Automatically inject Bower components into the HTML file自動把Bower的組件注入到HTML檔案中
如果我們通過以下方式安裝組件
bower install jquery --savebower install sea.js --save
安裝後會在bower.json檔案中看到
{ "name": "framework-demo", "private": true, "dependencies": { "jquery": "~2.1.4", "jquery-ui": "~1.11.4", "knockout": "^3.3.0", "seajs": "^3.0.0" }}
在Gruntfile.js檔案中配置wirdep Task
wiredep: { app: { src: ['<%= config.app %>/index.html'], ignorePath: /^(\.\.\/)*\.\./ } }
執行grunt wiredep命令
在index.html檔案會把預設dependencies依賴中的組件自動注入到下面標籤中去。
<!-- bower:js --> <script src="/bower_components/jquery/dist/jquery.js"></script> <script src="/bower_components/jquery-ui/jquery-ui.js"></script> <script src="/bower_components/knockout/dist/knockout.js"></script> <script src="/bower_components/seajs/dist/sea.js"></script> <!-- endbower -->
wiredep中的option中的參數devDependencies:注入開發版中的相依元件;dependencies:注入相依元件;directory: 'the directory of your Bower packages.' 存放bower包的目錄,這個目錄是'.bowerrc'檔案中的.directory