Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
browser-sync
Advanced tools
Browser-sync is a powerful tool for web developers that provides live reloading, synchronized browser testing, and other features to streamline the development process. It helps in creating a seamless development experience by automatically refreshing the browser whenever files are changed, and it can also synchronize interactions across multiple devices.
Live Reloading
This feature allows the browser to automatically reload whenever files in the specified directory are changed. The code sample sets up a server to serve files from the 'app' directory and watches for changes in any files within that directory, triggering a reload when changes are detected.
const browserSync = require('browser-sync').create();
browserSync.init({
server: './app'
});
browserSync.watch('app/**/*.*').on('change', browserSync.reload);
Synchronized Browsing
Synchronized browsing ensures that interactions like clicks and scrolls are mirrored across all connected devices. The code sample initializes Browser-sync with ghost mode enabled for clicks and scrolls, allowing these interactions to be synchronized.
const browserSync = require('browser-sync').create();
browserSync.init({
server: './app',
ghostMode: {
clicks: true,
scroll: true
}
});
Proxying an Existing Server
This feature allows Browser-sync to act as a proxy for an existing server, enabling live reloading and synchronized browsing without changing the server configuration. The code sample sets up Browser-sync to proxy requests to 'yourlocal.dev'.
const browserSync = require('browser-sync').create();
browserSync.init({
proxy: 'yourlocal.dev'
});
Live-server is a simple development HTTP server with live reload capability. It is easier to set up compared to Browser-sync but offers fewer features. It is ideal for quick prototyping and small projects.
Webpack-dev-server is a development server that provides live reloading and HMR (Hot Module Replacement) for projects using Webpack. It is more complex to set up but integrates deeply with the Webpack build process, making it suitable for larger projects with complex build requirements.
Gulp-connect is a plugin for Gulp that provides a web server with live reload capability. It is useful for projects that already use Gulp for task automation, offering a seamless way to add live reloading to the development workflow.
Keep multiple browsers & devices in sync when building websites.
##Features
##When is it useful? It's pretty useful when used with a single browser, watching a CSS file for changes & injecting it. But the real power comes when you're building responsive sites and using multiple devices/monitors because it can keep all browsers in sync & make your workflow much faster.
##Using Grunt? There's a plugin for that
##How to install it?
npm install -g browser-sync
####If that doesn't work on a mac, try
sudo npm install -g browser-sync
##How to use it
Browser-sync is a command-line tool & the -g
from the command above makes it available everywhere on your system. Just cd
into your website and run one of the commands below. If any further instructions are needed, you'll be notified on the command line.
###Examples
Watch ALL CSS files in a directory for changes
browser-sync --files "app/css/*.css"
Watch ALL CSS files & HTML files in a directory for changes
browser-sync --files "app/css/*.css, app/*.html"
Watch ALL CSS files for changes with a static server
browser-sync --files "app/css/*.css" --server
Watch ALL CSS files for changes with a static server & specify that the base dir should be "app"
browser-sync --files "app/css/*.css" --server "app"
Watch ALL CSS files for changes with a static server & specify that the base dir should be "app" & specify the index file (note the missing l)
browser-sync --files "app/css/*.css" --server "app" --index "index.htm"
Watch ALL CSS files for changes with a static server & specify that the base dir should be "app" & with browser-sync disabled
browser-sync --files "app/css/*.css" --server "app" --ghostMode false
###Example config file If you want to, you can provide a config file instead of having to remember all of the command above. Also, a config file allows you to be more specific with options. Here's an example of one that you would put in the root of your project.
module.exports = {
files: "app/css/**/*.css",
host: "192.168.1.1",
ghostMode: {
links: true,
forms: true,
scroll: true
},
server: {
baseDir: "app"
}
};
Now, if you called the file config.js
, you'd simple run
browser-sync --config config.js
##All available options for use in config file
###files - (default: null)
// single file
files: "app/css/style.css"
// multiple files
files: ["app/css/style.css", "app/css/ie.css"]
// multiple files with glob
files: "app/css/*.css"
// multiple globs
files: ["app/css/*.css", "app/**.*.html"]
###debugInfo - (default: true)
// Don't fill my terminal with info
debugInfo: false
// Give me as much info as possible
debugInfo: true
###host - (default: null)
// Leave this set as null & browser-sync will try to figure out the correct IP to use.
host: null
// Override host detection if you know the correct IP to use
host: "192.168.1.1"
###ghostMode - (default: { links: true, forms: true, scroll: true} )
// Here you can disable each feature individually
ghostMode: {
links: true,
forms: true,
scroll: true
}
// Or switch them all off in one go
ghostMode: false
###server - (default: null)
// Serve files from the app directory
server: {
baseDir: "app"
}
// Serve files from the root directory
server: {
baseDir: "./"
}
###open - (default: true) - when used with server
// Launch a browser window at the correct location
open: true
// Stop the browser from automatically opening
open: false
#Full config file example
Save this as anything-you-like.js
module.exports = {
files: "app/css/**/*.css",
debugInfo: true,
host: "192.168.1.1",
ghostMode: {
links: true,
forms: true,
scroll: true
},
server: {
baseDir: "app"
},
open: false
};
Now you can use it by calling it from the command-line
browser-sync --config anything-you-like.js
Copyright (c) 2013 Shane Osbourne Licensed under the MIT license.
FAQs
Live CSS Reload & Browser Syncing
We found that browser-sync demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.