-
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.
feat: Add support for extraGlobals (#24)
New option `extraGlobals`. Value will be merged into global scope during render.
- Loading branch information
1 parent
1e34dd1
commit a953ce9
Showing
12 changed files
with
2,631 additions
and
2,414 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 @@ | ||
12.8 |
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
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
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
13 changes: 13 additions & 0 deletions
13
tests/test-cases/extraGlobals/__snapshots__/extraGlobals.test.js.snap
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`with extra globals in scope should render a HTML file 1`] = ` | ||
Object { | ||
"a": Object { | ||
"index.html": "<html> | ||
<body> | ||
anExtraGlobalValue: An Extra Global Value | ||
</body> | ||
</html>", | ||
}, | ||
} | ||
`; |
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,24 @@ | ||
const MemoryFS = require("memory-fs"); | ||
const webpack = require("webpack"); | ||
const path = require("path"); | ||
|
||
const config = require("./webpack.config"); | ||
const getDirContentsSync = require("../../utils/getDirContentsSync"); | ||
|
||
describe("with extra globals in scope", () => { | ||
const renderDirectory = path.join(process.cwd(), "dist", "render"); | ||
|
||
it("should render a HTML file", async done => { | ||
const compiler = webpack(config); | ||
|
||
const memoryFs = new MemoryFS(); | ||
compiler.outputFileSystem = memoryFs; | ||
|
||
compiler.run(error => { | ||
expect(error).toBe(null); | ||
const contents = getDirContentsSync(renderDirectory, { fs: memoryFs }); | ||
expect(contents).toMatchSnapshot(); | ||
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,9 @@ | ||
/* global anExtraGlobalValue */ | ||
|
||
export default function exampleRender() { | ||
return `<html> | ||
<body> | ||
anExtraGlobalValue: ${anExtraGlobalValue} | ||
</body> | ||
</html>`; | ||
} |
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,31 @@ | ||
const path = require("path"); | ||
|
||
const srcPath = path.resolve(__dirname, "./src"); | ||
const paths = { | ||
renderEntry: path.resolve(srcPath, "render.js") | ||
}; | ||
|
||
const HtmlRenderPlugin = require("../../../src"); | ||
|
||
const renderDirectory = path.join(process.cwd(), "dist", "render"); | ||
const plugin = new HtmlRenderPlugin({ | ||
routes: [{ route: "/a/", extra: "a" }], | ||
renderDirectory, | ||
extraGlobals: { | ||
anExtraGlobalValue: "An Extra Global Value" | ||
} | ||
}); | ||
|
||
module.exports = { | ||
name: "render", | ||
target: "node", | ||
mode: "production", | ||
entry: paths.renderEntry, | ||
output: { | ||
libraryExport: "default", | ||
library: "static", | ||
libraryTarget: "umd2", | ||
filename: "render-[name]-[contenthash].js" | ||
}, | ||
plugins: [plugin.render()] | ||
}; |
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
Oops, something went wrong.