Skip to content

Commit

Permalink
feat: ✨ use open-browser-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
huruji committed Feb 24, 2019
1 parent 6ecfd20 commit 5bac211
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"mini-css-extract-plugin": "^0.5.0",
"nice-is-url": "^1.0.2",
"open": "^0.0.5",
"open-browser-plugin": "^1.0.3",
"ora": "^3.1.0",
"postcss-loader": "^3.0.0",
"posthtml": "^0.11.3",
Expand Down
41 changes: 2 additions & 39 deletions packages/cli/plugins/devServer-plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
const { HotModuleReplacementPlugin } = require('webpack');
// const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
// const LiveReloadPlugin = require('webpack-livereload-plugin');
const open = require('open');

let hasOpen = false;
class openBrowser {
constructor(url) {
this.url = url || 'http://google.com';
}

apply(compiler) {
const url = this.url;
compiler.hooks.afterEmit.tap('openBrowser', () => {
if (!hasOpen) open(url);
hasOpen = true;
});
}
}
const OpenBrowserPlugin = require('open-browser-plugin');

module.exports.apply = (compiler) => {
let isWatch = false;
Expand All @@ -28,7 +11,6 @@ module.exports.apply = (compiler) => {
compiler.hook('beforeCompile', (config) => {
if (!isWatch) return;
const dist = config.toConfig().output.path;
const entrys = config.toConfig().entry;
config.devServer
.contentBase(dist)
.hot(true)
Expand All @@ -37,26 +19,7 @@ module.exports.apply = (compiler) => {
.stats('errors-only')
.watchContentBase(true);

config.plugin('openbrowser').use(openBrowser, [`http://localhost:${port}`]);
// config.plugin('livereload').use(LiveReloadPlugin, [
// {
// hostname: 'localhost'
// }
// ]);
// config.plugin('browserSync').use(BrowserSyncPlugin, [
// {
// host: 'localhost',
// port,
// server: {
// baseDir: [dist]
// }
// }
// ]);
// for (const entry in entrys) {
// if (config.entryPoints.has(entry)) {
// config.entry('index').prepend('webpack-dev-server/client?http://localhost:7001');
// }
// }
config.plugin('openbrowser').use(OpenBrowserPlugin, [`http://localhost:${port}`]);
config.plugin('hot').use(HotModuleReplacementPlugin);
});
};

0 comments on commit 5bac211

Please sign in to comment.