Skip to content

Commit 8bf936b

Browse files
nickiaconischriseppstein
authored andcommitted
fix(webpack): Compatibility w/ webpack-dev-server.
filter out fake paths injected by the dev server prevents ENOENT errors when Analyzer tries to open fake paths
1 parent 6140280 commit 8bf936b

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

packages/@css-blocks/webpack/src/Plugin.ts

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export class CssBlocksPlugin
117117
entries = flatten<string>(objectValues(webpackEntry));
118118
}
119119

120+
// Zomg webpack-dev-server, injecting fake paths into the entry points.
121+
entries = entries.filter(entry => !/\/webpack-dev-server\/|^webpack\/hot\/dev-server$/.test(entry));
122+
120123
let pending: PendingResult = this.analyzer.analyze("", entries)
121124
// If analysis fails, drain our BlockFactory, add error to compilation error list and propagate.
122125
.catch((err: Error) => {

packages/@css-blocks/webpack/test/plugin-test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class PluginTest {
4242
});
4343
}
4444

45+
@skip @test "works with HotModuleReplacementPlugin"() {
46+
return execTest("hello", undefined, "dev-server");
47+
}
48+
4549
@skip @test "integrates with templates"() {
4650
return templateConfig().then(config => {
4751
return runWebpackAsPromise(config).then(() => {

packages/@css-blocks/webpack/test/util/execTest.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { LoaderOptions } from "../../src/LoaderOptions";
77
import { WebpackAny } from "../../src/Plugin";
88
import { EntryTypes, config as basicConfig } from "../configs/basicConfig";
99

10-
import { BLOCK_FIXTURES_DIRECTORY, DIST_DIRECTORY } from "./testPaths";
10+
import { BLOCK_FIXTURES_DIRECTORY, DIST_DIRECTORY, WEBPACK_DEV_SERVER_PATH } from "./testPaths";
1111
const CR = /\r/g;
1212

1313
// This test harness was adapted from the sass-loader test suite.
1414

15-
export function execTest(testId: string, options?: LoaderOptions, entryFormat: "string" | "object" | "array" = "string") {
15+
export function execTest(testId: string, options?: LoaderOptions, entryFormat: "string" | "object" | "array" | "dev-server" = "string") {
1616
const entryPath: string = path.join(BLOCK_FIXTURES_DIRECTORY, testId + ".block.css");
1717
let entry: EntryTypes = entryPath;
1818

@@ -22,6 +22,9 @@ export function execTest(testId: string, options?: LoaderOptions, entryFormat: "
2222
else if (entryFormat === "object") {
2323
entry = { main: entryPath };
2424
}
25+
else if (entryFormat === "dev-server") {
26+
entry = [WEBPACK_DEV_SERVER_PATH, "webpack/hot/dev-server", entryPath];
27+
}
2528

2629
return runWebpackAsPromise(basicConfig(entry, options))
2730
.then(() => {

packages/@css-blocks/webpack/test/util/testPaths.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const DIST_DIRECTORY = path.resolve(__dirname, "..", "..");
44
export const FIXTURES_DIRECTORY = path.resolve(DIST_DIRECTORY, "..", "test", "fixtures");
55
export const BLOCK_FIXTURES_DIRECTORY = path.resolve(FIXTURES_DIRECTORY, "blocks");
66
export const BLOCK_LOADER_PATH = require.resolve("../../src/loader.js");
7+
export const WEBPACK_DEV_SERVER_PATH = path.join(__dirname, "node_modules", "webpack-dev-server", "client", "index?http://localhost:8080");

0 commit comments

Comments
 (0)