Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/issue 1230 exclude script tags of type application/json from bundling #1231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/src/lib/resource-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ async function trackResourcesForRoute(html, compilation, route) {
const scripts = await Promise.all(root.querySelectorAll('script')
.filter(script => (
isLocalLink(script.getAttribute('src')) || script.rawText)
&& script.rawAttrs.indexOf('importmap') < 0)
&& script.rawAttrs.indexOf('importmap') < 0
&& script.getAttribute('type') !== 'application/json')
.map(async(script) => {
const src = script.getAttribute('src');
const optimizationAttr = script.getAttribute('data-gwd-opt');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Build Greenwood With: ', function() {
it('should have two <script> tag with inline script in the <head>', function() {
const scriptTagInline = Array.from(dom.window.document.querySelectorAll('head > script:not([src])')).filter(tag => !tag.getAttribute('data-gwd'));

expect(scriptTagInline.length).to.be.equal(4);
expect(scriptTagInline.length).to.be.equal(5);
});

it('should have the expected inline content from inline <script> tag one in index.html', async function() {
Expand All @@ -99,6 +99,13 @@ describe('Build Greenwood With: ', function() {
expect(scriptTagSrcTwo.textContent).to.contain('document.getElementsByClassName("output-script-inline-three")[0].innerHTML="script tag module inline three"');
});

it('should have the expected <script> tag of type application/json', async function() {
const scriptJson = Array.from(dom.window.document.querySelectorAll('head > script[type="application/json"]'));

expect(scriptJson.length).to.equal(1);
expect(JSON.parse(scriptJson[0].textContent).message).to.equal('calmer than you are');
});

});

describe('non module <script src="..."></script> tag in the <head>', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
</script>

<script src="/scripts/non-module.js"></script>

<script type="application/json">
{"message": "calmer than you are" }
</script>
</head>

<body>
Expand Down
Loading