Summary of the use of grunt

Source: Internet
Author: User

1, Installation Grunt:
If you have previously installed the old version 0.3, please uninstall first:
NPM Uninstall-g Grunt

To install the grunt command line (CLI):
NPM install-g GRUNT-CLI

Note 1:-g on behalf of the global installation, Grunt has two versions: server-side version (grunt) and client version (GRUNT-CLI).

NOTE 2: Installing GRUNT-CLI is not equivalent to installing the grunt. The task of the grunt CLI is simple: Invoke the grunt in the same directory as gruntfile. The advantage of this is that you are allowed to install multiple versions of Grunt on the same system. Instead of installing a command-line interface, Grunt uses the module structure to install the appropriate modules as needed. These modules should be installed locally because different projects may require different versions of the same module.

After the above command has been executed, the grunt command is added to your system path and can then be executed in any directory.

To create a new grunt project:
Suppose this project is installed in the D-Packing directory, we first progress D disk:
D:

To create a project folder:
mkdir TestProject

Enter folder:
CD TestProject

Then add two files to the root directory of your project folder: Package.json and Gruntfile.

Package.json: This file is used by NPM to store the project's metadata in order to publish this project as a NPM module.
Gruntfile: This file is named Gruntfile.js or Gruntfile.coffee, used to configure or define tasks (Task) and load Grunt plug-ins.

To create a Package.json file:
Package.json should be placed in the root directory of the project, in the same directory as Gruntfile, and should be submitted with the project's source code. Most grunt-init templates will automatically create project-specific Package.json files.

Method One: Perform the NPM init command (according to the default Grunt-init template, guide you to create a "basic" Package.json file):
NPM Init

Fill in the information according to the prompts (Du Yun blank):

Name: (GRUNTT)//module names: can only contain lowercase alphanumeric and underscores, and if empty, use the project folder name instead of version: (0.0.0)//Version Number Description://Description: Will search the NPM list Show entry point: (index.js)//Module Entry file Test command://test script git repository://git warehouse address keywords://keywords : For NPM search, multiple keywords separated by spaces Author://Author License: (bsd-2-clause)//Kaiyuan protocol

Method Two: Manually create the Package.json file, add the project/module description information:

{' name ': ' My-project ', ' Version ': ' 0.1.0 '}

Report:
Package.json Official documents
A more complete Package.json file

To install the grunt and grunt Plug-ins:
Method One: Manually add, modify Package.json file:

{"Name": "My-project", "Version": "0.1.0", "devdependencies": {"grunt": "~0.4.1", "Grunt-contrib-cssmin": "~0.7.0 "  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.