Được TopGit lập chỉ mục từ metadata GitHub: johnpapa/lite-server có 2.3k sao, viết chủ yếu bằng JavaScript. Lightweight node server
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Lightweight development only node server that serves a web app, opens it in the browser, refreshes when html or javascript change, injects CSS changes using sockets, and has a fallback page when a route is not found.
Why
BrowserSync does most of what we want in a super fast lightweight development server. It serves the static content, detects changes, refreshes the browser, and offers many customizations.
When creating a SPA there are routes that are only known to the browser. For example, /customer/21 may be a client side route for an Angular app. If this route is entered manually or linked to directly as the entry point of the Angular app (aka a deep link) the static server will receive the request, because Angular is not loaded yet. The server will not find a match for the route and thus return a 404. The desired behavior in this case is to return the index.html (or whatever starting page of the app we have defined). BrowserSync does not automatically allow for a fallback page. But it does allow for custom middleware. This is where lite-server steps in.
lite-server is a simple customized wrapper around BrowserSync to make it easy to serve SPAs.
Installation and Usage
The recommended installation method is a local NPM install for your project:
With the above script entry, you can then start lite-server via:
npm run dev
Other options for running locally installed NPM binaries is discussed in this Stack Overflow question: How to use package installed locally in node_modules
Using on the fly
lite-server can be used with npx
npx lite-server
Global Installation
lite-server can be also installed globally, if preferred:
npm install --global lite-server
# To run:
lite-server
Custom Configuration
The default behavior serves from the current folder, opens a browser, and applies a HTML5 route fallback to ./index.html.
lite-server uses BrowserSync, and allows for configuration overrides via a local bs-config.json or bs-config.js file in your project.
You can provide custom path to your config file via -c or --config= run time options:
lite-server -c configs/my-bs-config.js
For example, to change the server port, watched file paths, and base directory for your project, create a bs-config.json in your project's folder:
You can also provide custom path to your base directory --baseDir= run time options:
lite-server --baseDir="dist"
A more complicated example with modifications to the server middleware can be done with a bs-config.js file, which requires the module.exports = { ... }; syntax:
module.exports = {
server: {
middleware: {
// overrides the second middleware default with new settings
1: require('connect-history-api-fallback')({
index: '/index.html',
verbose: true,
}),
},
},
};
The bs-config.js file may also export a function that receives the lite-server Browsersync instance as its only argument. While not required, the return value of this function will be used to extend the default lite-server configuration.
module.exports = function (bs) {
return {
server: {
middleware: {
// overrides the second middleware default with new settings
1: require('connect-history-api-fallback')({
index: '/index.html',
verbose: true,
}),
},
},
};
};
NOTE: Keep in mind that when using middleware overrides the specific middleware module must be installed in your project. For the above example, you'll need to do:
A list of the entire set of BrowserSync options can be found in its docs: http://www.browsersync.io/docs/options/
Testing
When using lite-server to run end to end tests, we may not want to log verbosely. We may also want to prevent the browser from opening. These options in the bs-config.js will silence all logging from lite-server:
CSS with Angular 2 is embedded thus even though BrowserSync detects the file change to CSS, it does not inject the file via sockets. As a workaround, injectChanges defaults to false.
Contributing
Fork and clone it
Install dependencies: npm install
Create a feature branch: git checkout -b new-feature
Commit changes: git commit -am 'Added a feature'
Run static code analysis and unit tests: npm test
Push to the remote branch: git push origin new-feature
johnpapa/lite-server thuộc nhóm Backend trên TopGit, cùng 7 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về johnpapa/lite-server ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/johnpapa/lite-server là nguồn chính thức.
johnpapa/lite-server có bao nhiêu sao?
johnpapa/lite-server có 2.3k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/johnpapa/lite-server. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
johnpapa/lite-server có phải mã nguồn mở không?
Có — johnpapa/lite-server phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/johnpapa/lite-server.
johnpapa/lite-server có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho johnpapa/lite-server. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
johnpapa/lite-server là gì?
johnpapa/lite-server (johnpapa/lite-server) là dự án JavaScript trên GitHub. Theo mô tả gốc: Lightweight node server
johnpapa/lite-server so với các dự án Backend khác thế nào?
johnpapa/lite-server được TopGit xếp vào nhóm Backend, với 2.3k sao GitHub và viết bằng JavaScript. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
lite-server có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về lite-server.