Skip to content

Commit 23a7509

Browse files
faceyspaceyshellscape
authored andcommitted
resolve merge conflict for PR #151 (#187)
* added support for multi-compiler configuration see: webpack/webpack-dev-server#641 * fixed compiler reference in the multi-compiler patch * moved new method to the getFilenamefromUrl file, adjusted tests accordingly * adjusted test to verify multi-compiler mode is functioning correctly when more than one outputPath is present * added a few more tests to verify multi-compiler handling * added a few more tests to verify multi-compiler handling * added a few more tests to verify multi-compiler handling * resolve merge conflict for PR #151 * format * readme * chore($deleteFile) remove yarn.lock * chore($revert) revert readme and package.json to pre-fork state
1 parent ae920f1 commit 23a7509

File tree

5 files changed

+111
-19
lines changed

5 files changed

+111
-19
lines changed

lib/GetFilenameFromUrl.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,31 @@ function getFilenameFromUrl(publicPath, outputPath, url) {
3333

3434
}
3535

36-
module.exports = getFilenameFromUrl;
36+
// support for multi-compiler configuration
37+
// see: https://github.com/webpack/webpack-dev-server/issues/641
38+
function getPaths(publicPath, compiler, url) {
39+
var compilers = compiler && compiler.compilers;
40+
if(Array.isArray(compilers)) {
41+
var compilerPublicPath;
42+
for(var i = 0; i < compilers.length; i++) {
43+
compilerPublicPath = compilers[i].options
44+
&& compilers[i].options.output
45+
&& compilers[i].options.output.publicPath;
46+
if(url.indexOf(compilerPublicPath) === 0) {
47+
return {
48+
publicPath: compilerPublicPath,
49+
outputPath: compilers[i].outputPath
50+
};
51+
}
52+
}
53+
}
54+
return {
55+
publicPath: publicPath,
56+
outputPath: compiler.outputPath
57+
};
58+
}
59+
60+
module.exports = function(publicPath, compiler, url) {
61+
var paths = getPaths(publicPath, compiler, url);
62+
return getFilenameFromUrl(paths.publicPath, paths.outputPath, url);
63+
};

middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function(compiler, options) {
3636
return goNext();
3737
}
3838

39-
var filename = getFilenameFromUrl(context.options.publicPath, context.compiler.outputPath, req.url);
39+
var filename = getFilenameFromUrl(context.options.publicPath, context.compiler, req.url);
4040
if(filename === false) return goNext();
4141

4242

@@ -74,7 +74,7 @@ module.exports = function(compiler, options) {
7474
}
7575
}
7676

77-
webpackDevMiddleware.getFilenameFromUrl = getFilenameFromUrl.bind(this, context.options.publicPath, context.compiler.outputPath);
77+
webpackDevMiddleware.getFilenameFromUrl = getFilenameFromUrl.bind(this, context.options.publicPath, context.compiler);
7878
webpackDevMiddleware.waitUntilValid = shared.waitUntilValid;
7979
webpackDevMiddleware.invalidate = shared.invalidate;
8080
webpackDevMiddleware.close = shared.close;

test/GetFilenameFromUrl.test.js

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var should = require("should");
22
var getFilenameFromUrl = require("../lib/GetFilenameFromUrl");
33

44
function testUrl(options) {
5-
var url = getFilenameFromUrl(options.publicPath, options.outputPath, options.url);
5+
var url = getFilenameFromUrl(options.publicPath, options, options.url);
66
should.strictEqual(url, options.expected);
77
}
88

@@ -33,47 +33,47 @@ describe("GetFilenameFromUrl", function() {
3333
url: "/test.html?foo=bar",
3434
outputPath: "/",
3535
publicPath: "/",
36-
expected: "/test.html",
36+
expected: "/test.html"
3737
}, {
3838
url: "/a.js",
3939
outputPath: "/dist",
4040
publicPath: "/",
41-
expected: "/dist/a.js",
41+
expected: "/dist/a.js"
4242
}, {
4343
url: "/b.js",
4444
outputPath: "/",
4545
publicPath: undefined,
46-
expected: "/b.js",
46+
expected: "/b.js"
4747
}, {
4848
url: "/c.js",
4949
outputPath: undefined,
5050
publicPath: undefined,
51-
expected: "/c.js",
51+
expected: "/c.js"
5252
}, {
5353
url: "/more/complex/path.js",
5454
outputPath: "/a",
5555
publicPath: "/",
56-
expected: "/a/more/complex/path.js",
56+
expected: "/a/more/complex/path.js"
5757
}, {
5858
url: "/more/complex/path.js",
5959
outputPath: "/a",
6060
publicPath: "/complex",
61-
expected: false,
61+
expected: false
6262
}, {
6363
url: "c.js",
6464
outputPath: "/dist",
6565
publicPath: "/",
66-
expected: false, // publicPath is not in url, so it should fail
66+
expected: false // publicPath is not in url, so it should fail
6767
}, {
6868
url: "/bar/",
6969
outputPath: "/foo",
7070
publicPath: "/bar/",
71-
expected: "/foo",
71+
expected: "/foo"
7272
}, {
7373
url: "/bar/",
7474
outputPath: "/",
7575
publicPath: "http://localhost/foo/",
76-
expected: false,
76+
expected: false
7777
}, {
7878
url: "http://test.domain/test/sample.js",
7979
outputPath: "/",
@@ -94,7 +94,70 @@ describe("GetFilenameFromUrl", function() {
9494
outputPath: "/",
9595
publicPath: "/",
9696
expected: "/pathname with spaces.js"
97-
},
97+
}, {
98+
url: "/js/sample.js",
99+
compilers: [
100+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
101+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
102+
],
103+
outputPath: "/root",
104+
publicPath: "/",
105+
expected: "/foo/sample.js"
106+
}, {
107+
url: "/css/sample.css",
108+
compilers: [
109+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
110+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
111+
],
112+
outputPath: "/root",
113+
publicPath: "/",
114+
expected: "/bar/sample.css"
115+
}, {
116+
url: "/other/sample.txt",
117+
compilers: [
118+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
119+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
120+
],
121+
outputPath: "/root",
122+
publicPath: "/",
123+
expected: "/root/other/sample.txt"
124+
}, {
125+
url: "/js/sample.js",
126+
compilers: [
127+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
128+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
129+
],
130+
outputPath: "/root",
131+
publicPath: "/test/",
132+
expected: "/foo/sample.js"
133+
}, {
134+
url: "/css/sample.css",
135+
compilers: [
136+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
137+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
138+
],
139+
outputPath: "/root",
140+
publicPath: "/test/",
141+
expected: "/bar/sample.css"
142+
}, {
143+
url: "/other/sample.txt",
144+
compilers: [
145+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
146+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
147+
],
148+
outputPath: "/root",
149+
publicPath: "/test/",
150+
expected: false
151+
}, {
152+
url: "/test/sample.txt",
153+
compilers: [
154+
{ outputPath: "/foo", options: { output: { publicPath: "/js/" } } },
155+
{ outputPath: "/bar", options: { output: { publicPath: "/css/" } } }
156+
],
157+
outputPath: "/root",
158+
publicPath: "/test/",
159+
expected: "/root/sample.txt"
160+
}
98161
];
99162
results.forEach(testUrl);
100163
});

test/Server.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ describe("Server", function() {
150150
var instance = middleware(compiler, {
151151
stats: "errors-only",
152152
quiet: true,
153-
publicPath: "/",
153+
publicPath: "/"
154154
});
155155
app.use(instance);
156156
listen = listenShorthand(done);
157157
});
158158
after(close);
159159

160160
it("request to both bundle files", function(done) {
161-
request(app).get("/foo.js")
161+
request(app).get("/js1/foo.js")
162162
.expect(200, function() {
163-
request(app).get("/bar.js")
163+
request(app).get("/js2/bar.js")
164164
.expect(200, done);
165165
});
166166
});

test/fixtures/server-test/webpack.array.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ module.exports = [{
33
entry: "./foo.js",
44
output: {
55
filename: "foo.js",
6-
path: "/"
6+
path: "/js1",
7+
publicPath: "/js1/"
78
}
89
}, {
910
context: __dirname,
1011
entry: "./bar.js",
1112
output: {
1213
filename: "bar.js",
13-
path: "/"
14+
path: "/js2",
15+
publicPath: "/js2/"
1416
}
1517
}];

0 commit comments

Comments
 (0)