Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #21 from coltonw/https
Browse files Browse the repository at this point in the history
Open the correct page when webpack-dev-server has https turned on.
  • Loading branch information
alansouzati authored Feb 13, 2017
2 parents c6d40df + 15c0ead commit 7a0e9c2
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ function deleteDistributionFolder() {
}
}

function runDevServer(compiler) {
function runDevServer(compiler, devServerConfig) {
console.log(
`${delimiter}: Starting dev server...`
);
getDevServerConfig().then((devServerConfig) => {
const devServer = new WebpackDevServer(compiler, devServerConfig);
const devServer = new WebpackDevServer(compiler, devServerConfig);

devServer.listen(PORT, (err, result) => {
if (err) {
throw err;
}
});
}).catch(err => console.log(err));
devServer.listen(PORT, (err, result) => {
if (err) {
throw err;
}
});
}

function build(config) {
Expand Down Expand Up @@ -80,40 +78,45 @@ function build(config) {
const compiler = webpack(config, handleResponse);

if (ENV === 'development') {
let firstCompilation = true;
compiler.plugin('done', (stats) => {
const statHandler = (stat) => {
if (stat.compilation.errors.length) {
errorHandler(stat.compilation.errors);
} else {
console.log(stat.toString({
chunks: false,
colors: true
}));

console.log(
`${delimiter}: ${chalk.green('success')}`
);
getDevServerConfig().then((devServerConfig) => {
let firstCompilation = true;
compiler.plugin('done', (stats) => {
const statHandler = (stat) => {
if (stat.compilation.errors.length) {
errorHandler(stat.compilation.errors);
} else {
console.log(stat.toString({
chunks: false,
colors: true
}));

if (firstCompilation) {
console.log(
`${delimiter}: Opening the browser at http://localhost:${PORT}`
`${delimiter}: ${chalk.green('success')}`
);

opener(`http://localhost:${PORT}`);
if (firstCompilation) {
// https can be an object or just a boolean but either way will
// be truthy when it is turned on
const protocol = devServerConfig.https ? 'https' : 'http';
console.log(
`${delimiter}: Opening the browser at ${protocol}://localhost:${PORT}`
);

opener(`${protocol}://localhost:${PORT}`);
}

firstCompilation = false;
}
};

firstCompilation = false;
if (stats.stats) { // multiple stats
stats.stats.forEach(statHandler);
} else {
statHandler(stats);
}
};

if (stats.stats) { // multiple stats
stats.stats.forEach(statHandler);
} else {
statHandler(stats);
}
});
runDevServer(compiler, devServerConfig);
});
runDevServer(compiler);
}
});
}
Expand Down

0 comments on commit 7a0e9c2

Please sign in to comment.