Skip to content

Commit 3f58f60

Browse files
author
Ciuca, Alexandru
committed
Write to real file-system and give compile result via http route
1 parent 8e8f540 commit 3f58f60

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

bin/webpack-dev-server.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ var optimist = require("optimist")
3737

3838
.describe("port", "The port").default("port", 8080)
3939

40-
.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost");
40+
.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost")
41+
42+
.boolean("useRealFileSystem").describe("useRealFileSystem", "Write bundles to real file system instead of in-memory virtual file system").default("useRealFileSystem", false);
4143

4244
require("webpack/bin/config-optimist")(optimist);
4345

@@ -53,6 +55,10 @@ if(argv.host !== "localhost" || !options.host)
5355

5456
if(argv.port !== 8080 || !options.port)
5557
options.port = argv.port;
58+
59+
if (argv.useRealFileSystem) {
60+
options.useRealFileSystem = true;
61+
}
5662

5763
if(!options.publicPath) {
5864
options.publicPath = firstWpOpt.output && firstWpOpt.output.publicPath || "";
@@ -65,7 +71,9 @@ if(!options.outputPath)
6571
if(!options.filename)
6672
options.filename = firstWpOpt.output && firstWpOpt.output.filename;
6773
[].concat(wpOpt).forEach(function(wpOpt) {
68-
wpOpt.output.path = "/";
74+
if (!options.useRealFileSystem) {
75+
wpOpt.output.path = "/";
76+
}
6977
});
7078
if(!options.hot)
7179
options.hot = argv["hot"];

lib/Server.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var httpProxy = require("http-proxy");
1010
var proxy = new httpProxy.createProxyServer();
1111
var serveIndex = require("serve-index");
1212
var historyApiFallback = require("connect-history-api-fallback");
13+
var stripAnsi = require("strip-ansi");
1314

1415
function Server(compiler, options) {
1516
// Default options
@@ -21,7 +22,7 @@ function Server(compiler, options) {
2122

2223
this.hot = options.hot;
2324
this.headers = options.headers;
24-
25+
2526
// Listening for events
2627
var invalidPlugin = function() {
2728
if(this.io) this.io.sockets.emit("invalid");
@@ -33,7 +34,7 @@ function Server(compiler, options) {
3334
this._sendStats(this.io.sockets, stats.toJson());
3435
this._stats = stats;
3536
}.bind(this));
36-
37+
3738
// Prepare live html page
3839
var livePage = this.livePage = new StreamCache();
3940
fs.createReadStream(path.join(__dirname, "..", "client", "live.html")).pipe(livePage);
@@ -108,6 +109,45 @@ function Server(compiler, options) {
108109
writeDirectory(options.publicPath || "/", path);
109110
res.end('</body></html>');
110111
}.bind(this));
112+
113+
app.get("/webpack-compile-stats", function(req, res) {
114+
res.setHeader("Content-Type", "application/json");
115+
116+
if (!this._stats) {
117+
res.statusCode = 500;
118+
res.end("No stats found for last compilation");
119+
return;
120+
}
121+
122+
var stats = this._stats;
123+
124+
var output = {};
125+
126+
if (stats.hasErrors()) {
127+
var errors = stats.compilation.errors;
128+
129+
output.errors = [];
130+
errors.forEach(function(err) {
131+
output.errors.push({
132+
name: err.name,
133+
message: stripAnsi(err.message),
134+
file: err.module.resource,
135+
error: {
136+
line: err.error.lineNumber,
137+
column: err.error.column,
138+
description: err.error.description,
139+
message: stripAnsi(err.error.toString()),
140+
},
141+
loc: err.dependencies[0] ? err.dependencies[0].loc : undefined
142+
});
143+
});
144+
}
145+
146+
res.write(JSON.stringify(output));
147+
148+
res.end();
149+
150+
}.bind(this));
111151

112152
if (options.proxy) {
113153
var paths = Object.keys(options.proxy);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"stream-cache": "~0.0.1",
1818
"strip-ansi": "^2.0.1",
1919
"supports-color": "^1.3.1",
20-
"webpack-dev-middleware": "^1.0.7"
20+
"webpack-dev-middleware": "https://github.com/ssnau/webpack-dev-middleware/tarball/0d2beb349e2b12858e7845bbb4bbac4f821ae835"
2121
},
2222
"devDependencies": {
2323
"css-loader": "~0.7.1",

0 commit comments

Comments
 (0)