windows下使用grunt

來源:互聯網
上載者:User

標籤:

grunt官網:http://www.gruntjs.org/

一、安裝grunt

先安裝node,在http://www.nodejs.org/可以下載安裝包直接安裝。在命令列下運行:

npm install -g grunt-cli

即可安裝grunt。

二、建立項目

建立web項目:my-project-name,項目目錄如下:

在項目根目錄下建立Gruntfile.js和package.json檔案。樣本如下:

/* package.json */{    "name": "my-project-name",    "version": "1.0.0",    "description": "this is nodejs demo",    "main": "index.js",    "scripts": {        "test": "echo \"Error: no test specified\" && exit 1"    },    "devDependencies": {        "grunt": "^0.4.5",        "grunt-contrib-concat": "^0.5.0",        "grunt-contrib-jshint": "~0.6.0",        "grunt-contrib-nodeunit": "~0.2.0",        "grunt-contrib-uglify": "~0.2.2"    },    "author": "yuki",    "license": "ISC"}
/* Gruntfile.js */module.exports = function(grunt){    grunt.initConfig({        pkg: grunt.file.readJSON(‘package.json‘),        concat: {            options: {                separator: ‘;‘            },            dist: {                src: [‘src/**/*.js‘],                dest: ‘dist/<%= pkg.name %>.js‘            }        },        uglify: {            options: {                banner: ‘/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n‘            },            dist: {                files: {                    ‘dist/<%= pkg.name %>.min.js‘: [‘<%= concat.dist.dest %>‘]                }            }        },        jshint: {            files: [‘gruntfile.js‘, ‘src/**/*.js‘, ‘test/**/*.js‘],            options: {                //這裡是覆蓋JSHint預設配置的選項                globals: {                    jQuery: true,                    console: true,                    module: true,                    document: true                }            }        }    });    grunt.loadNpmTasks(‘grunt-contrib-uglify‘);    grunt.loadNpmTasks(‘grunt-contrib-jshint‘);    grunt.loadNpmTasks(‘grunt-contrib-concat‘);    grunt.registerTask(‘test‘, [‘jshint‘, ‘concat‘]);    grunt.registerTask(‘default‘, [‘jshint‘,‘concat‘, ‘uglify‘]);};

三、進入項目目錄下,安裝grunt,並運行命令:

npm install

安裝項目所依賴的包,項目下會產生node_models目錄,如下所示:

運行命令:grunt,將執行‘default‘ task。

 

windows下使用grunt

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.