Skip to content

Commit f5fd0c0

Browse files
author
evilebottnawi
committed
Chore: initial public release.
1 parent 3fde8d3 commit f5fd0c0

8 files changed

+350
-3
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.gitattributes

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Autodetect text files
2+
* text=auto
3+
4+
# ...Unless the name matches the following overriding patterns
5+
6+
# Definitively text files
7+
.* text eol=lf
8+
*.php text eol=lf
9+
*.css text eol=lf
10+
*.js text eol=lf
11+
*.html text eol=lf
12+
*.json text eol=lf
13+
*.less text eol=lf
14+
*.scss text eol=lf
15+
*.sass text eol=lf
16+
*.txt text eol=lf
17+
*.md text eol=lf
18+
*.markdown text eol=lf
19+
*.xml text eol=lf
20+
*.json text eol=lf
21+
*.bat text eol=lf
22+
*.sh text eolf=lf
23+
*.svg text eol=lf
24+
*.sql text eol=lf
25+
*.xml text eol=lf
26+
*.yml text eol=lf
27+
28+
# Ensure those won't be messed up with
29+
*.ico binary
30+
*.png binary
31+
*.jpg binary
32+
*.jpeg binary
33+
*.webp binary
34+
*.gif binary
35+
*.eot binary
36+
*.ttf binary
37+
*.woff binary
38+
*.woff2 binary
39+
*.mp3 binary
40+
*.m4a binary
41+
*.mp4 binary
42+
*.m4p binary
43+
*.acc binary

.gitignore

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Logs
22
logs
3-
*.log
4-
npm-debug.log*
3+
*.log*
54

65
# Runtime data
76
pids
87
*.pid
98
*.seed
9+
*.lock
1010

1111
# Directory for instrumented libs generated by jscoverage/JSCover
1212
lib-cov
@@ -35,3 +35,22 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
39+
# gitkeep
40+
!.gitkeep
41+
42+
# IDE
43+
.idea
44+
*.iml
45+
46+
# VSCode metadata
47+
.vscode
48+
49+
# Mac files
50+
.DS_Store
51+
52+
# Ignore minified files
53+
*.min.*
54+
55+
# Caches
56+
.eslintcache

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sudo: false
2+
3+
language: node_js
4+
5+
node_js:
6+
- '7'
7+
- '6'
8+
- '5'
9+
- '4'
10+
11+
cache:
12+
directories:
13+
- node_modules
14+
15+
before_install:
16+
- npm prune
17+
- npm update

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
This project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
# 0.0.1 - 2017-02-14
8+
9+
- Chore: initial public release.

README.md

+65-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
11
# browser-sync-dev-hot-webpack-plugin
2-
Combines BrowserSync, webpack-dev-middleware, and webpack-hot-middleware into one ezpz plugin.
2+
3+
[![NPM version](https://img.shields.io/npm/v/browser-sync-dev-hot-webpack-plugin.svg)](https://www.npmjs.org/package/browser-sync-dev-hot-webpack-plugin)
4+
[![Travis Build Status](https://img.shields.io/travis/itgalaxy/browser-sync-dev-hot-webpack-plugin/master.svg?label=build)](https://travis-ci.org/itgalaxy/browser-sync-dev-hot-webpack-plugin)
5+
[![dependencies Status](https://david-dm.org/itgalaxy/browser-sync-dev-hot-webpack-plugin/status.svg)](https://david-dm.org/itgalaxy/browser-sync-dev-hot-webpack-plugin)
6+
[![devDependencies Status](https://david-dm.org/itgalaxy/browser-sync-dev-hot-webpack-plugin/dev-status.svg)](https://david-dm.org/itgalaxy/browser-sync-dev-hot-webpack-plugin?type=dev)
7+
8+
Combines BrowserSync, webpack-dev-middleware, and webpack-hot-middleware into one plugin.
9+
10+
## Install
11+
12+
```shell
13+
npm install --save-dev browser-sync-dev-hot-webpack-plugin
14+
```
15+
16+
## Usage
17+
18+
```js
19+
const BROWSER_SYNC_OPTIONS = {};
20+
const DEV_MIDDLEWARE_OPTIONS = {
21+
publicPath: '/my/public/path'
22+
};
23+
const HOT_MIDDLEWARE_OPTIONS = {};
24+
25+
const webpackConfig = {
26+
// Some options...
27+
plugins: [
28+
// Other plugins...
29+
new BrowserSyncHotPlugin({
30+
browserSyncOptions: BROWSER_SYNC_OPTIONS,
31+
devMiddlewareOptions: DEV_MIDDLEWARE_OPTIONS,
32+
hotMiddlewareOptions: HOT_MIDDLEWARE_OPTIONS,
33+
callback() {
34+
console.log('Callback')
35+
}
36+
})
37+
// Other plugins...
38+
]
39+
// Some options...
40+
};
41+
42+
module.exports = webpackConfig;
43+
```
44+
45+
## Options
46+
47+
See related packages docs.
48+
49+
## Related
50+
51+
- [browser-sync](https://github.com/browsersync/browser-sync) - Keep multiple browsers & devices
52+
in sync when building websites.
53+
54+
- [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) - Offers a dev middleware for webpack,
55+
which arguments a live bundle to a directory.
56+
57+
- [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middleware) - Webpack hot reloading
58+
you can attach to your own server.
59+
60+
## Contribution
61+
62+
Feel free to push your code if you agree with publishing under the MIT license.
63+
64+
## [Changelog](CHANGELOG.md)
65+
66+
## [License](LICENSE)

package.json

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"name": "browser-sync-dev-hot-webpack-plugin",
3+
"version": "0.0.1",
4+
"description": "Combines BrowserSync, webpack-dev-middleware, and webpack-hot-middleware into one plugin",
5+
"license": "MIT",
6+
"author": "itgalaxy <[email protected]>",
7+
"contributors": [
8+
{
9+
"name": "Alexander Krasnoyarov",
10+
"email": "[email protected]",
11+
"url": "https://vk.com/sterling_archer"
12+
}
13+
],
14+
"repository": {
15+
"type": "https",
16+
"url": "https://github.com/itgalaxy/browser-sync-dev-hot-webpack-plugin"
17+
},
18+
"keywords": [
19+
"webpack",
20+
"webpack-plugin",
21+
"browsersync",
22+
"browser-sync",
23+
"livereload",
24+
"serve",
25+
"webpack-dev-middleware",
26+
"webpack-hot-middleware"
27+
],
28+
"bugs": {
29+
"url": "https://github.com/itgalaxy/browser-sync-dev-hot-webpack-plugin/issues"
30+
},
31+
"files": [
32+
"!**/__tests__"
33+
],
34+
"main": "src/BrowserSyncDevHotWebpackPlugin.js",
35+
"dependencies": {
36+
"deepmerge": "^1.3.2"
37+
},
38+
"devDependencies": {
39+
"ajv-cli": "^1.1.0",
40+
"eslint": "^3.15.0",
41+
"eslint-plugin-ava": "^4.0.0",
42+
"eslint-plugin-import": "^2.2.0",
43+
"eslint-plugin-itgalaxy": "^38.0.0",
44+
"eslint-plugin-jsx-a11y": "^4.0.0",
45+
"eslint-plugin-lodash": "^2.1.0",
46+
"eslint-plugin-node": "^4.0.0",
47+
"eslint-plugin-promise": "^3.3.0",
48+
"eslint-plugin-react": "^6.6.0",
49+
"eslint-plugin-unicorn": "^2.0.0",
50+
"npmpub": "^3.1.0",
51+
"npm-run-all": "^4.0.0",
52+
"package-schema": "^1.0.0",
53+
"remark-cli": "^2.0.0",
54+
"remark-lint": "^5.0.0",
55+
"remark-preset-lint-itgalaxy": "^4.0.0"
56+
},
57+
"peerDependencies": {
58+
"browser-sync": "^2.0.0",
59+
"webpack": "^1 || ^2 || ^2.0.0-beta || ^2.1.0-beta || ^2.2.0-rc.0",
60+
"webpack-dev-middleware": "^1.0.0",
61+
"webpack-hot-middleware": "^2.0.0"
62+
},
63+
"scripts": {
64+
"lint:eslint": "eslint . --ignore-path .gitignore --color",
65+
"lint:package": "ajv -s ./node_modules/package-schema/schema.json -d package --errors=text",
66+
"lint:remark": "remark . -i .gitignore -f -q",
67+
"lint": "npm-run-all -l --parallel lint:*",
68+
69+
"test": "npm run lint",
70+
71+
"release": "npmpub"
72+
},
73+
"eslintConfig": {
74+
"rules": {
75+
"strict": ["error", "global"]
76+
},
77+
"parserOptions": {
78+
"sourceType": "script"
79+
},
80+
"extends": [
81+
"plugin:itgalaxy/esnext",
82+
"plugin:itgalaxy/node"
83+
],
84+
"root": true
85+
}
86+
}

src/BrowserSyncDevHotWebpackPlugin.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strict';
2+
3+
/* eslint-disable node/no-missing-require */
4+
const webpackDevMiddleware = require('webpack-dev-middleware');
5+
const webpackHotMiddleware = require('webpack-hot-middleware');
6+
const browserSync = require('browser-sync');
7+
/* eslint-enable node/no-missing-require */
8+
const merge = require('deepmerge');
9+
10+
class BrowserSyncDevHotWebpackPlugin {
11+
constructor(options) {
12+
this.watcher = null;
13+
this.compiler = null;
14+
this.options = merge.all([
15+
{
16+
browserSyncOptions: {},
17+
callback() {}, // eslint-disable-line no-empty-function
18+
devMiddlewareOptions: {
19+
noInfo: true,
20+
stats: false
21+
},
22+
hotMiddlewareOptions: {}
23+
},
24+
options
25+
]);
26+
}
27+
28+
apply(compiler) {
29+
if (this.options.disable) {
30+
return;
31+
}
32+
33+
this.compiler = compiler;
34+
35+
compiler.plugin('done', () => {
36+
if (!this.watcher) {
37+
this.watcher = browserSync.create();
38+
compiler.plugin('compilation', () => this.watcher.notify('Rebuilding...'));
39+
this.start();
40+
}
41+
});
42+
}
43+
44+
start() {
45+
let browserSyncURLLocal = 'initialization';
46+
let browserSyncURLExternal = 'initialization';
47+
let browserSyncURLUI = 'initialization';
48+
let browserSyncURLUIExternal = 'initialization';
49+
const watcherConfig = merge.all([
50+
{
51+
proxy: {
52+
middleware: this.middleware(),
53+
proxyReq: [
54+
(proxyReq) => {
55+
proxyReq.setHeader('X-Browser-Sync-URL-Local', browserSyncURLLocal);
56+
proxyReq.setHeader('X-Browser-Sync-URL-External', browserSyncURLExternal);
57+
proxyReq.setHeader('X-Browser-Sync-URL-UI', browserSyncURLUI);
58+
proxyReq.setHeader('X-Browser-Sync-URL-UI-External', browserSyncURLUIExternal);
59+
proxyReq.setHeader('X-Dev-Middleware', 'On');
60+
proxyReq.setHeader('X-Hot-Middleware', 'On');
61+
}
62+
]
63+
}
64+
},
65+
this.options.browserSyncOptions
66+
]);
67+
68+
this.watcher.init(watcherConfig, (error, bs) => {
69+
if (error) {
70+
throw error;
71+
}
72+
73+
const URLs = bs.getOption('urls');
74+
75+
browserSyncURLLocal = URLs.get('local');
76+
browserSyncURLExternal = URLs.get('external');
77+
browserSyncURLUI = URLs.get('ui');
78+
browserSyncURLUIExternal = URLs.get('ui-external');
79+
80+
this.options.callback.bind(this);
81+
});
82+
}
83+
84+
middleware() {
85+
const hotMiddlewareOptions = merge.all([
86+
{
87+
log: this.watcher.notify.bind(this.watcher)
88+
},
89+
this.options.hotMiddlewareOptions
90+
]);
91+
92+
this.webpackDevMiddleware = webpackDevMiddleware(this.compiler, this.options.devMiddlewareOptions);
93+
this.webpackHotMiddleware = webpackHotMiddleware(this.compiler, hotMiddlewareOptions);
94+
95+
return [this.webpackDevMiddleware, this.webpackHotMiddleware];
96+
}
97+
}
98+
99+
module.exports = BrowserSyncDevHotWebpackPlugin;

0 commit comments

Comments
 (0)