Grunt_1從安裝開始建立一個基本的Grunt,grunt_1建立grunt

來源:互聯網
上載者:User

Grunt_1從安裝開始建立一個基本的Grunt,grunt_1建立grunt

Grunt的介紹:http://www.gruntjs.net/getting-started

檔案架構:https://github.com/zhangsai521314/Grunt

1:安裝Git Bash,https://git-scm.com/download/win(安裝一路next)

2:安裝node.js+npm,:https://nodejs.org/en/download/

注意:到這個選項的時候選這個

3:Git Bush安裝Grunt用戶端:npm install -g grunt-cli

4:開啟git bash查看安裝是否成功。

4:項目結構圖:

5:把package.json放到MvcApplication1檔案夾下。package.json的基本內容。

{  "name": "my-project-name",  "version": "0.1.0",  "devDependencies": {    "grunt": "^0.4.5",    "grunt-contrib-concat": "^0.5.0",    "grunt-contrib-cssmin": "^0.10.0",    "grunt-contrib-uglify": "^0.5.1"  }}

6:git bash進入MvcApplication1檔案夾下。執行npm install,如果此時沒有package.json檔案則會報錯。

7:執行成功

8:在目錄下添加Gruntfile.js

// 常用的功能:    // uglify:壓縮    // cssmin:css操作    // imagemin:圖片操作    // htmlmin:html操作module.exports = function(grunt) {    grunt.initConfig({        pkg: grunt.file.readJSON('package.json'),        uglify: {//壓縮            options: {                banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'//頭資訊            },            build: {             //動態檔案對應,當運行任務時會自動找到cwd參數下的src參數下所有符合規則的js檔案             //添加或刪除檔案時不需要更新 Gruntfile。             files: [                {                 expand: true,       // 啟用動態擴充                 cwd: 'Scripts/',    // 源檔案匹配都相對此目錄                 src: ['*.js'],      // 匹配規則                 dest: 'dest/js/',   // 任務目標儲存路徑                 ext: '.min.js',     // 目標檔案路徑中檔案的副檔名                 extDot: 'first'     // 副檔名始於檔案名稱的第一個點號                },             ],            }        },        cssmin: {            options: {                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',                            },            //動態檔案對應,當運行任務時會自動找到cwd參數下的src參數下所有符合規則的css檔案            build: {                files: [{                    expand: true,                    cwd: 'Content/',                    src:  ['*.css','**/*.css'],                    dest: 'dest/css/',                    ext: '.min.css',                    extDot: 'first'                }]            }        }                });            //載入concat和uglify外掛程式,分別對於合并和壓縮     grunt.loadNpmTasks('grunt-contrib-uglify');//    grunt.loadNpmTasks('grunt-contrib-cssmin');    //當執行 Grunt 且不通過參數指定任務時,將執行本配置的內容任務。    grunt.registerTask('default', ['uglify','cssmin']);}

9:使用grunt命令執行壓縮css, grunt cssmin

 

 

 我在執行壓縮js的時候有點問題,沒有把檔案夾下匹配的所有js壓縮。待解決

寫文不易,轉載需註明出處:http://www.cnblogs.com/zszs/p/5662541.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.