gatsby-plugin-no-javascript
gatsby-plugin-no-javascript copied to clipboard
javascript is not stripped when building with path prefix
The plugin works as expected as long as I run a vanilla gatsby build
.
However, when using the path prefix option, and then running gatsby build --prefix-paths
, the script elements will not be filtered from the resulting page.
instead, they are included with the correct path prefix, like this:
<link as="script" rel="preload" href="/foo/framework-26f52d65ffe097091d9a.js"/>
Can confirm this is happening.
Me too. I can't use the plugin now on a blog that lives in a subdirectory.
I think that prefixing script.name
with __PATH_PREFIX__
in
`/${script.name}` === headComponent.props.href &&
and in
return pageScripts.find((script): boolean => postBodyComponent.type === 'script' && `/${script.name}` === postBodyComponent.props.src) === undefined
should help. Please mind that I have not tested this thoroughly.
I also noticed that the "polyfill" script does not get removed, so the existing filter should be updated to cover this script too.
I also ran into having my polyfill spared.
I think that prefixing
script.name
with__PATH_PREFIX__
in`/${script.name}` === headComponent.props.href &&
and in
return pageScripts.find((script): boolean => postBodyComponent.type === 'script' && `/${script.name}` === postBodyComponent.props.src) === undefined
should help. Please mind that I have not tested this thoroughly.
I also noticed that the "polyfill" script does not get removed, so the existing filter should be updated to cover this script too.
Thanks a lot, @mcagalj! Your tip was very helpful.
I did my own fix on the outside of the npm package, as I am a little newbie with package management.
If anyone needs the correction urgently, here it is. Just create the gatsby-ssr.js file at the root of the project
https://gist.github.com/joaocarloscabral/1173496642a15772d13815126ee1dc73