Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

materliu/grunt-localhosts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

31 Commits

Repository files navigation

grunt-localhosts v0.1.0 NPM Version NPM

Change your local machine hosts.

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-localhosts --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-localhosts');

change localhosts task

Run this task with the grunt localhosts command.

This task was designed to be used in conjunction with another task grunt server which open local server binds on localhosts 127.0.0.1, but if your page requests some cgi server for example cgi.qun.qq.com, the Same-Origin Policy will not allow you do this by localhosts. At the time you can change your local hosts file 127.0.0.1 qun.qq.com, then you can access the cgi server by CORS just simply open you local pages at "qun.qq.com/index.html", by the way, change the grunt connect open page to url "qun.qq.com" not localhost !

Options

rules

Type: Array Default: `empty array'

just statement which localhost you want to set or remove !

rules: [{
 ip: '127.0.0.1', // point domain "A" to address "B"
 hostname: 'qun.qq.com',
 type: 'set'
}]
rules: [{
 domain: 'baidu.com', // point domain "A" to domain "B"
 hostname: 'qun.qq.com',
 type: 'set'
}]

Usage examples

Basic Use

In this example, grunt localhosts (or more verbosely, grunt localhosts:set) will change your localhosts as you wish, obviously you can use 'grunt localhosts:remove' too.

// Project configuration.
grunt.initConfig({
 localhosts: {
 set : {
 options: {
 rules: [{
 ip: '127.0.0.1',
 hostname: 'qun.qq.com',
 type: 'set'
 }, {
 ip: '127.0.0.1',
 hostname: 'find.qq.com',
 type: 'set'
 }, {
 domain: 'baidu.com', // point domain "A" to domain "B"
 hostname: 'find.qq.com',
 type: 'set'
 }]
 }
 },
 remove : {
 options: {
 rules: [{
 ip: '127.0.0.1',
 hostname: 'qun.qq.com',
 type: 'remove'
 }]
 }
 }
 },
});
grunt.registerTask('serve', function (target) {
 grunt.task.run([
 'concurrent:server',
 "localhosts:set",
 'connect:livereload',
 'open:server',
 'watch'
 ]);
});
grunt.registerTask('build', [
 'localhosts:remove', // clear previously set localhosts
 '.......' // content removed for brevity
]);

Release History

  • 2016年01月28日 v0.1.0 handle writing file permission denied
  • 2016年01月27日 v0.0.9 Add dns lookup support. thx @Filip Spiridonov
  • 2014年10月24日 v0.0.8 Add multiple rules support. thx @NameFILIP
  • 2012年04月10日 v0.0.7 Add manufacturer info.
  • 2012年04月09日 v0.0.5 Bug fix.
  • 2012年04月08日 v0.0.3 Officially released.
  • 2012年04月08日 v0.0.2 Work in progress, not yet officially released, just add some necessary node_modules !
  • 2012年04月04日 v0.0.1 Work in progress, not yet officially released.

About

grunt-localhosts is an open-source project by Tencent which builds on top of Node.js.

Used by people within (JOIN US)

Tencent Xiaomi


Task submitted by materliu

This file was generated on Fri Apr 4 2014 22:38:50.

About

one grunt task which can make change to your local host.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

AltStyle によって変換されたページ (->オリジナル) /