Web development tools: http-server, grunt, http-servergrunt

Source: Internet
Author: User

Web development tools: http-server, grunt, http-servergrunt


Author: Songyang

This article is from Ashura road and is prohibited for commercial purposes. For more information, see the source.

Link: http://blog.csdn.net/fansongy/article/details/44121699






Http-server

It is a simple service deployment. Compared with Express, It is lighter. It is just a service building tool and can not be installed in the project directory. Installation and use:

npm install -g http-server

After successful installation, use:

http-server -a hostip -p port

You can pull the web applications in the current directory.

Of course, if you are a teenager, you can install it in a local project. At startup, run the following command in the root directory of the web application:

node ../node_modules/http-server/bin/http-server

Other parameters-hYou can view it. There is a trap. Sometimes, restarting the service page after changing the file does not take effect immediately to delete the browser cache.

Grunt

This product is an automated plug-in, which can be compiled, compressed, and tested separately. It can be powerful as long as it is lazy. Its official website is here. I feel that localization is doing well and it is estimated that it is quite beautiful. Install and run:

npm install -g grunt-cli

This is a starter, something like creating a project in Express. We recommend that you install it globally. It is estimated that each project will be used.

You can run the following command to install the SDK in a project:

npm install grunt --save-dev

Download and save it to package. json. The same is true for joining other friends. Common methods include:

  • Grunt-contrib-jshint detects js files
  • Grunt-contrib-uglify obfuscation Compression
  • Grunt-contrib-nodeunit node single test
  • Grunt-contrib-watch detects file changes

After grunt is installed, you must configure it. Create a Gruntfile. js file in the directory of the package. json file at the same level. According to the official documents, Gruntfile consists of the following parts:

  • "Wrapper" Function
  • Project and task Configuration
  • Load grunt plug-ins and tasks
  • Custom task

An example is as follows:

module.exports=function(grunt){    grunt.initConfig({        pkg:grunt.file.readJSON('package.json'),        uglify:{            options:{                banner:'/*!<%=pkg.name%> <%=grunt.template.today("yyyy-mm-dd")%> */\n'            },              build:{                src:'src/<%=pkg.name%>.js',                dest:'build/<%= pkg.name %>.min.js'            }           }       });     grunt.loadNpmTasks('grunt-contrib-uglify');    grunt.registerTask('default',['uglify']);};

Compile and run gruntOr grunt uglifyYou can compress the package name file under the src directory to the build directory. There are still many things that this function can do. See another article for reference.

If you think this article is helpful to you, you can stick to it, not only won't like it, but also let more people see it...

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.