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-h
You 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
grunt
Or
grunt uglify
You 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...