-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add render errors to compilation
- Loading branch information
1 parent
18c1c99
commit 1f7d36c
Showing
7 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = class RenderError extends Error { | ||
constructor(error) { | ||
super( | ||
`html-render-webpack-plugin: An error occured during render: \n${error}` | ||
); | ||
|
||
this.name = "RenderError"; | ||
|
||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const MemoryFS = require("memory-fs"); | ||
const webpack = require("webpack"); | ||
|
||
describe("Render HTML from in-config Plugin", () => { | ||
it("should render a HTML file", async done => { | ||
const compiler = webpack(require("./webpack.errors.config")); | ||
|
||
const memoryFs = new MemoryFS(); | ||
compiler.outputFileSystem = memoryFs; | ||
|
||
compiler.run((error, result) => { | ||
// Render errors do not show up as build errors | ||
expect(error).toBe(null); | ||
// Errors show up in compilation | ||
expect(result.toJson({ all: false, errors: true }).errors).toEqual( | ||
expect.arrayContaining([expect.stringContaining("Example error")]) | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = async () => { | ||
const bar = "foo"; | ||
return bar; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function exampleRender() { | ||
throw new Error("Example error"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const path = require("path"); | ||
|
||
const srcPath = path.resolve(__dirname, "./src"); | ||
const paths = { | ||
renderEntry: path.resolve(srcPath, "render.js"), | ||
clientEntry: path.resolve(srcPath, "client.js") | ||
}; | ||
|
||
module.exports = [ | ||
{ | ||
name: "client", | ||
target: "web", | ||
mode: "production", | ||
entry: paths.clientEntry, | ||
output: { | ||
filename: "client-[name]-[contenthash].js" | ||
} | ||
}, | ||
{ | ||
dependencies: ["client"], | ||
name: "render", | ||
target: "node", | ||
mode: "production", | ||
entry: paths.renderEntry, | ||
output: { | ||
libraryExport: "default", | ||
library: "static", | ||
libraryTarget: "umd2", | ||
filename: "render-[name]-[contenthash].js" | ||
} | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require("path"); | ||
const merge = require("webpack-merge"); | ||
const defaultConfig = require("./webpack.default.config"); | ||
const HtmlRenderPlugin = require("../../../src"); | ||
|
||
const renderDirectory = path.join(process.cwd(), "dist", "render"); | ||
|
||
const htmlRenderPlugin = new HtmlRenderPlugin({ renderDirectory }); | ||
|
||
module.exports = [ | ||
merge(defaultConfig[0], { | ||
plugins: [htmlRenderPlugin] | ||
}), | ||
merge(defaultConfig[1], { | ||
plugins: [htmlRenderPlugin.render()] | ||
}) | ||
]; |