Skip to content

Way to disable External Resource lookup for script & link tags #226

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

Closed
btakita opened this issue Aug 24, 2020 · 4 comments · Fixed by #262
Closed

Way to disable External Resource lookup for script & link tags #226

btakita opened this issue Aug 24, 2020 · 4 comments · Fixed by #262
Labels
bug Something isn't working

Comments

@btakita
Copy link
Contributor

btakita commented Aug 24, 2020

I'm attempting to add svelte-preprocess to my rollup.config build. I have been using svelte components to dynamically load external script & link tags.

<svelte:head>
  <script src={_versioned('/client/pdfmake.min.js')}></script>
  <script src={_versioned('/client/vfs_fonts.js')}></script>
</svelte:head>

When running the build, I get the error:

[svelte-preprocess] The file  "/path/to/component/{_versioned('/client/pdfmake.min.js')}" was not found.
[svelte-preprocess] The file  "/path/to/component/{_versioned('/client/vfs_fonts.js')}" was not found.

It seems like svelte-preprocess is attempting to look for an External Reference. Is there a way to disable this check for some script & link tags?

I do have a workaround atm...

<svelte:head>
  <script {...{src: _versioned('/client/pdfmake.min.js')}}></script>
  <script {...{src: _versioned('/client/vfs_fonts.js')}}></script>
</svelte:head>
@kaisermann
Copy link
Member

Hey @btakita 👋

Sorry for the delay and thanks for the report! Fixed in 4.4.1 🥳

@plmrry
Copy link

plmrry commented May 18, 2021

hi @kaisermann — would it be possible to disable external files altogether?

I have an SSR component that needs to render a script tag like this:

<script src="js/main.js" /></script>

I don't want svelte-preprocess to try to import js/main.js

@kaisermann
Copy link
Member

Hey @plmrry 👋 currently, there's no straightforward way to disable the external file lookup. Is your js/main.js being inserted by the preprocessor? Can you share a minimal repro?

In theory, if js/main.js doesn't exist at that (relative) path on build time, the preprocessor wouldn't touch the tag.

@plmrry
Copy link

plmrry commented May 19, 2021

@kaisermann The problem is, it does exist, but as an unbundled file, but I want to render a script tag that will point to the bundled file. Will try to make a minimal demo when I get the chance...

I can get around it by doing this, just a bit hacky

<script src={"js/main.js"}></script>

There's also this case (which isn't covered by the previous PR fix):

<script src="js/{myFile}.js"></script>

(Although I guess as you pointed out, in this case it would just not find the file and emit a warning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants