stencil-site icon indicating copy to clipboard operation
stencil-site copied to clipboard

Missing docs for data-stencil-namespace script attribute

Open KevinCarnaille2 opened this issue 3 years ago • 0 comments

Stencil version: @stencil/core@^2.8.0

Description

Hello team,

I think it could be handy to add some documentation about this specific part of generated bundle (the bundle is my-namespace.esm.js, www output):

    // @ts-ignore
    const scriptElm = BUILD.scriptDataOpts || BUILD.safari10 || BUILD.dynamicImportShim
        ? Array.from(doc.querySelectorAll('script')).find((s) => new RegExp(`\/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) ||
            s.getAttribute('data-stencil-namespace') === NAMESPACE)
        : null;

Adding data-stencil-namespace="my-namespace" is a really useful fallback, if for example we need to use a bundle with a hash into it, or simply with a different namespace for example :

<script src="/www/build/my-namespace-ej6jau8hu4.esm.js" />

In this specific case, the RegExp is not matching, but using the above HTML attribute fix the issue (scriptElm is not defined if we load some polyfills).

I'm not sure it can be considered as an actual @stencil/core issue or a documentation one, so sorry if it's not relevant here, but I guess it's easier to add some doc for this, than fixing the RegExp itself for the moment :)

KevinCarnaille2 avatar Oct 01 '21 08:10 KevinCarnaille2