-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deletes empty output client-side JavaScript bundles.
This updates the Rollup config to avoid generating empty bundles. This used to be a warning, but now the bundles are not emitted at all. The build process will properly skip injecting a pointless `<script>` tag, so everything works as expected.
- Loading branch information
Showing
5 changed files
with
107 additions
and
4 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,47 @@ | ||
load("//:index.bzl", "prerender_pages", "web_resources_devserver") | ||
load("//tools/jasmine:defs.bzl", "jasmine_web_test_suite") | ||
load("//tools/typescript:defs.bzl", "ts_project") | ||
|
||
prerender_pages( | ||
name = "site", | ||
entry_point = "./site.js", | ||
prerender = ":prerender", | ||
scripts = ":scripts", | ||
) | ||
|
||
ts_project( | ||
name = "prerender", | ||
srcs = ["site.tsx"], | ||
deps = [ | ||
"//:node_modules/@rules_prerender/preact", | ||
"//:node_modules/preact", | ||
], | ||
) | ||
|
||
ts_project( | ||
name = "scripts", | ||
srcs = ["empty_script.mts"], | ||
) | ||
|
||
web_resources_devserver( | ||
name = "devserver", | ||
resources = ":site", | ||
) | ||
|
||
ts_project( | ||
name = "test_lib", | ||
srcs = ["test.mts"], | ||
testonly = True, | ||
deps = [ | ||
"//common/testing:devserver", | ||
"//common/testing:webdriver", | ||
"//:node_modules/@types/jasmine", | ||
], | ||
) | ||
|
||
jasmine_web_test_suite( | ||
name = "test", | ||
browsers = ["//tools/browsers:chromium-local"], | ||
data = [":devserver"], | ||
deps = [":test_lib"], | ||
) |
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 @@ | ||
// Empty script, should not be injected into the page. |
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 @@ | ||
import { PrerenderResource, renderToHtml, includeScript } from '@rules_prerender/preact'; | ||
|
||
export default function*(): Generator<PrerenderResource, void, void> { | ||
yield PrerenderResource.fromHtml('/index.html', renderToHtml( | ||
<html> | ||
<head> | ||
<meta charSet="utf8" /> | ||
<title>Empty script</title> | ||
</head> | ||
<body> | ||
<h2>Empty script</h2> | ||
|
||
{includeScript('./empty_script.mjs', import.meta)} | ||
</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,20 @@ | ||
import { useDevserver } from '../../common/testing/devserver.mjs'; | ||
import { useWebDriver } from '../../common/testing/webdriver.mjs'; | ||
|
||
describe('empty_scripts', () => { | ||
const devserver = useDevserver('examples/empty_script/devserver.sh'); | ||
const wd = useWebDriver(devserver); | ||
|
||
describe('index page', () => { | ||
it('renders without a script', async () => { | ||
const browser = wd.get(); | ||
await browser.url('/'); | ||
|
||
expect(await browser.$('h2').getText()).toBe('Empty script'); | ||
|
||
// Expect only the live reload script. | ||
const scripts = await browser.$$('script'); | ||
expect(scripts.length).toBe(1); | ||
}); | ||
}); | ||
}); |
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