-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print webpack console to browser console #1063
Changes from all commits
f6f958c
7c77b5c
d74e667
4223363
4721cfa
eca5338
4ca0a82
095332e
70db8dd
6bb4fd8
6d72910
68fb260
a31f46c
a29b0c1
a96a5d2
e7c29d4
34c840d
94502a0
d98bbc0
bd64321
dccf845
9716cf9
c64be22
5fc1b51
44e8c72
4219340
131b6da
8c8c229
27cb246
6cb0f62
068559b
2c68d7a
1978919
aab052d
a0fc7ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Status | ||
|
||
```shell | ||
node ../../bin/webpack-dev-server.js --open | ||
``` | ||
|
||
## What should happen | ||
|
||
The script should open the browser and show a heading with "Example: progress". | ||
|
||
In `app.js`, change the text and save. You should see the compilation progress in the browser console. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
// Change the following line and save to see the compilation status | ||
|
||
document.write('Change me to see compilation progress in console...'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Progress example</title> | ||
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script> | ||
</head> | ||
<body> | ||
<h1>Example: progress</h1> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
context: __dirname, | ||
entry: './app.js', | ||
devServer: { | ||
progress: true | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ function Server(compiler, options) { | |
this.headers = options.headers; | ||
this.clientLogLevel = options.clientLogLevel; | ||
this.clientOverlay = options.overlay; | ||
this.progress = options.progress; | ||
this.disableHostCheck = !!options.disableHostCheck; | ||
this.publicHost = options.public; | ||
this.allowedHosts = options.allowedHosts; | ||
|
@@ -52,6 +53,15 @@ function Server(compiler, options) { | |
const invalidPlugin = () => { | ||
this.sockWrite(this.sockets, 'invalid'); | ||
}; | ||
if (this.progress) { | ||
const progressPlugin = new webpack.ProgressPlugin((percent, msg, addInfo) => { | ||
percent = Math.floor(percent * 100); | ||
if (percent === 100) msg = 'Compilation competed'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll clean up that typo in a bit |
||
if (addInfo) msg = `${msg} (${addInfo})`; | ||
this.sockWrite(this.sockets, 'progress-update', { percent, msg }); | ||
}); | ||
compiler.apply(progressPlugin); | ||
} | ||
compiler.plugin('compile', invalidPlugin); | ||
compiler.plugin('invalid', invalidPlugin); | ||
compiler.plugin('done', (stats) => { | ||
|
@@ -563,6 +573,8 @@ Server.prototype.listen = function (port, hostname, fn) { | |
|
||
if (this.clientLogLevel) { this.sockWrite([conn], 'log-level', this.clientLogLevel); } | ||
|
||
if (this.progress) { this.sockWrite([conn], 'progress', this.progress); } | ||
|
||
if (this.clientOverlay) { this.sockWrite([conn], 'overlay', this.clientOverlay); } | ||
|
||
if (this.hot) this.sockWrite([conn], 'hot'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,14 @@ | |
} | ||
] | ||
}, | ||
"progress": { | ||
"description": "Shows compilation progress in browser console.", | ||
"anyOf": [ | ||
{ | ||
"type": "boolean" | ||
} | ||
] | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "progress": {
"description": "Shows compilation progress in browser console.",
"type": "boolean"
}, |
||
"key": { | ||
"description": "The contents of a SSL key.", | ||
"anyOf": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this super spammy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that it's an opt-in and the browser console doesn't have control characters, I don't believe it is.