Skip to content

Commit

Permalink
fix: Add exception-formatter dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jahredhope committed May 4, 2020
1 parent edd2d6b commit 96de450
Show file tree
Hide file tree
Showing 9 changed files with 930 additions and 801 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
node_modules
2 changes: 1 addition & 1 deletion MIGRATION_GUIDE_v1_to_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To recreate the previous behaviour pass the stats collector to render config
```js
plugins: [
htmlRenderPlugin.statsCollectorPlugin,
htmlRenderPlugin.rendererPlugin
htmlRenderPlugin.rendererPlugin,
];
```

Expand Down
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ See [the full example below](#example-client-assets).

Add `htmlRenderPlugin.statsCollectorPlugin` to the plugins of all configurations you want to get stats for.

Add `htmlRenderPlugin.render` to the plugin of the configuration you want to use to render html.
Add `htmlRenderPlugin.rendererPlugin` to the plugin of the configuration you want to use to render html.

HtmlRenderPlugin will then pass the [Webpack Stats](https://webpack.js.org/api/stats/) for those builds into your render function.

Expand All @@ -70,13 +70,13 @@ module.exports = [
{
name: "render",
target: "node", // Creates assets that render HTML that runs well in node
plugins: [htmlRenderPlugin.rendererPlugin]
plugins: [htmlRenderPlugin.rendererPlugin],
},
{
name: "client",
target: "web", // Creates files that run on the browser
plugins: [htmlRenderPlugin.statsCollectorPlugin]
}
plugins: [htmlRenderPlugin.statsCollectorPlugin],
},
];
```

Expand All @@ -95,13 +95,13 @@ The [webpack entry](https://webpack.js.org/concepts/entry-points/) to use when r
```js
module.exports = {
entry: {
myRender: "./src/myRender.js"
myRender: "./src/myRender.js",
},
plugins: [
new HtmlRenderPlugin({
renderEntry: "myRender"
}).render
]
renderEntry: "myRender",
}).render,
],
};
```

Expand All @@ -128,20 +128,20 @@ A route can be an object, containing a `route` parameter.
const routes = [
{
route: "en-us/contact",
language: "en-us"
language: "en-us",
},
{
route: "en-us/about",
language: "en-us"
language: "en-us",
},
{
route: "en-au/contact",
language: "en-au"
language: "en-au",
},
{
route: "/en-au/about",
language: "en-au"
}
language: "en-au",
},
];
```

Expand Down Expand Up @@ -217,14 +217,18 @@ Using the [Webpack Dev Server Node API](https://github.com/webpack/webpack-dev-s
```js
const htmlRenderPlugin = new HtmlRenderPlugin({
routes,
skipAssets: true
skipAssets: true,
});

const compiler = webpack(config);

const webpackDevServer = new WebpackDevServer(compiler);
const webpackDevServer = new WebpackDevServer(compiler, {
before: (app) => {
app.use(htmlRenderPlugin.createDevRouter());
},
});

webpackDevServer.use(htmlRenderPlugin.createDevRouter());
webpackDevServer.listen("8081");
```

**Note:** Ensure that you use the same htmlRenderPlugin created for your webpack configuration as you use for your dev server.
Expand Down Expand Up @@ -272,31 +276,31 @@ const path = require("path");

const { htmlRenderPlugin, htmlRenderClientPlugin } = createHtmlRenderPlugin({
mapStatsToParams: ({ webpackStats }) => ({
mainChunk: webpackStats.toJson().assetsByChunkName.main
})
mainChunk: webpackStats.toJson().assetsByChunkName.main,
}),
});

module.exports = [
{
name: "client",
target: "web",
output: {
filename: "client-[name]-[contenthash].js"
filename: "client-[name]-[contenthash].js",
},
entry: path.resolve("src", "client.js"),
plugins: [htmlRenderPlugin.statsCollectorPlugin]
plugins: [htmlRenderPlugin.statsCollectorPlugin],
},
{
name: "render",
target: "node",
output: {
libraryExport: "default",
libraryTarget: "umd2",
filename: "render-[name]-[contenthash].js"
filename: "render-[name]-[contenthash].js",
},
entry: path.resolve("src", "render.js"),
plugins: [htmlRenderPlugin.rendererPlugin]
}
plugins: [htmlRenderPlugin.rendererPlugin],
},
];
```

Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"build": "tsc --declaration",
"commit": "git-cz",
"lint.eslint": "eslint src/**/*.ts",
"lint.prettier": "prettier --check \"**/*.(js|ts)\"",
"lint.prettier": "prettier --check .",
"lint": "npm run lint.eslint && npm run lint.prettier",
"jest": "jest",
"prepublishOnly": "npm run build",
"test": "npm run lint && npm run jest",
"format": "prettier --write \"**/*.(js|ts)\"",
"format": "prettier --write .",
"release": "semantic-release"
},
"repository": {
Expand All @@ -32,34 +32,34 @@
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/express": "^4.17.3",
"@types/jest": "^25.1.4",
"@types/express": "^4.17.6",
"@types/jest": "^25.2.1",
"@types/memory-fs": "^0.3.2",
"@types/schema-utils": "^2.4.0",
"@types/webpack": "^4.41.8",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"commitizen": "4.0.3",
"@types/webpack": "^4.41.12",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"commitizen": "4.0.5",
"cz-conventional-changelog": "3.1.0",
"eslint": "6.8.0",
"exception-formatter": "^2.1.2",
"express": "^4.17.1",
"jest": "25.2.3",
"jest": "25.5.4",
"memoizee": "^0.4.14",
"memory-fs": "^0.5.0",
"prettier": "2.0.2",
"prettier": "2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"semantic-release": "17.0.4",
"ts-jest": "^25.2.1",
"ts-node": "^8.8.1",
"semantic-release": "17.0.7",
"ts-jest": "^25.4.0",
"ts-node": "^8.10.1",
"typescript": "^3.8.3",
"webpack": "4.42.1",
"webpack": "4.43.0",
"webpack-merge": "4.2.2"
},
"dependencies": {
"chalk": "^3.0.0",
"eval": "^0.1.4"
"chalk": "^4.0.0",
"eval": "^0.1.4",
"exception-formatter": "^2.1.2"
},
"config": {
"commitizen": {
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export = class HtmlRenderPlugin<Route extends BaseRoute = BaseRoute> {
clientCompilations.every(
(compilationStatus) => compilationStatus.isReady
);
const isRendererReady = () => isBuildReady() && renderer;
const isRendererReady = () => isBuildReady() && Boolean(renderer);

const renderQueue: Array<() => void> = [];
const flushRenderQueue = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`Use legacy api should render a HTML file 1`] = `
\\"route\\": \\"/\\",
\\"extra\\": \\"extra-value\\",
\\"assets\\": {
\\"main\\": \\"client-main-a71824fcc3a1cbe5b3a9.js\\"
\\"main\\": \\"client-main-2951ae76c7e3fa46fad4.js\\"
}
}
]</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Render WebpackStats should render a with asset names 1`] = `
Object {
"index.html": "{
\\"assets\\": {
\\"main\\": \\"client-main-a71824fcc3a1cbe5b3a9.js\\"
\\"main\\": \\"client-main-2951ae76c7e3fa46fad4.js\\"
}
}",
}
Expand Down
Loading

0 comments on commit 96de450

Please sign in to comment.