live-server的安装使用,临时服务器

本地开发常常需要搭建临时的服务,第一时间我们会想到用http-server

但现在流行修改文件浏览器自动刷新hot socketing(热拔插),如live-reload

若想浏览器自动打开项目,用opener

现在live-server实现了三个插件的所有功能,并且很简单就能启动一个看起来很专业的本地服务

NPM全局安装

 

npm install -g live-server

其它方式

 

 

git clone https://github.com/tapio/live-server
cd live-server
npm install # Local dependencies if you want to hack
npm install -g # Install globally

使用方法:

 

1. 在项目根目录使用命令

 

live-server

 

参数:

--port=NUMBER - select port to use, default: PORT env var or 8080
--host=ADDRESS - select host address to bind to, default: IP env var or 0.0.0.0 (“any address”)
--no-browser - suppress automatic web browser launching
--browser=BROWSER - specify browser to use instead of system default
--quiet | -q - suppress logging
--verbose | -V - more logging (logs all requests, shows all listening IPv4 interfaces, etc.)
--open=PATH - launch browser to PATH instead of server root
--watch=PATH - comma-separated string of paths to exclusively watch for changes (default: watch everything)
--ignore=PATH - comma-separated string of paths to ignore (anymatch-compatible definition)
--ignorePattern=RGXP - Regular expression of files to ignore (ie .*\.jade) (DEPRECATED in favor of --ignore)
--middleware=PATH - path to .js file exporting a middleware function to add; can be a name without path nor extension to reference bundled middlewares in middleware folder
--entry-file=PATH - serve this file (server root relative) in place of missing files (useful for single page apps)
--mount=ROUTE:PATH - serve the paths contents under the defined route (multiple definitions possible)
--spa - translate requests from /abc to /#/abc (handy for Single Page Apps)
--wait=MILLISECONDS - (default 100ms) wait for all changes, before reloading
--htpasswd=PATH - Enables http-auth expecting htpasswd file located at PATH
--cors - Enables CORS for any origin (reflects request origin, requests with credentials are supported)
--https=PATH - PATH to a HTTPS configuration module
--proxy=ROUTE:URL - proxy all requests for ROUTE to URL
--help | -h - display terse usage hint and exit
--version | -v - display version and exit


2. 把它放在package.jsonscripts下的server

 

 

"scripts": {
  "server": "live-server ./ --port=8081"
}

 

运行

npm run server


3. node

 

 

var liveServer = require("live-server");
 
var params = {
    port: 8181, // Set the server port. Defaults to 8080. 
    host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP. 
    root: "/public", // Set root directory that's being served. Defaults to cwd. 
    open: false, // When false, it won't load your browser by default. 
    ignore: 'scss,my/templates', // comma-separated string for paths to ignore 
    file: "index.html", // When set, serve this file for every 404 (useful for single-page applications) 
    wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec. 
    mount: [['/components', './node_modules']], // Mount a directory to a route. 
    logLevel: 2, // 0 = errors only, 1 = some, 2 = lots 
    middleware: [function(req, res, next) { next(); }] // Takes an array of Connect-compatible middleware that are injected into the server middleware stack 
};
liveServer.start(params);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Ubuntu 20.04 的 live-server 安装时,可以按照以下步骤进行操作: 1. 首先,下载 Ubuntu 20.04 的 Live Server ISO 镜像文件。你可以从 Ubuntu 官方网站(https://ubuntu.com/download/server)上找到下载链接。 2. 将 ISO 镜像文件写入到一个可启动的 USB 或 DVD 上。你可以使用工具如 Rufus(https://rufus.ie/)或 Etcher(https://www.balena.io/etcher/)来完成这一步。 3. 将启动介质插入到要安装 Ubuntu 20.04 的计算机上,并启动计算机。确保在计算机 BIOS 或 UEFI 设置中将启动介质设置为首选。 4. 在启动时,选择适当的语言和键盘布局。 5. 接下来,选择 "Install Ubuntu Server" 选项,然后按 Enter 键继续。 6. 在安装过程中,你需要选择语言、位置和键盘布局。这些选项将根据你的需求进行设置。 7. 在网络配置中,选择合适的网络连接方式,如 DHCP 或手动配置。 8. 选择主机名,并设置用户和密码。确保设置一个安全且易于记住的密码。 9. 根据你的需求,选择是否使用整个磁盘或手动分区来安装系统。 10. 系统安装完成后,会提示你重新启动计算机。按照指示操作,重新启动计算机。 11. 在重新启动后,你将看到一个登录提示符。使用你在安装过程中设置的用户名和密码进行登录。 12. 一旦登录成功,你就可以开始使用 Ubuntu 20.04 Live Server。 这些是基本的安装步骤,你可以根据需要进行自定义设置和配置。希望这些信息对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值