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

Some way to get advance warning of incorrect asset paths #326

Closed
Rich-Harris opened this issue Jan 14, 2021 · 2 comments
Closed

Some way to get advance warning of incorrect asset paths #326

Rich-Harris opened this issue Jan 14, 2021 · 2 comments
Labels
feature request New feature or request
Milestone

Comments

@Rich-Harris
Copy link
Member

Scenario: you have a file, like static/images/potato.jpg, referenced like so:

<img alt="potato" src="/images/potato.jpg">

But you also have a paths config:

// svelte.config.js
module.exports = {
  kit: {
    paths: {
      assets: 'https://cdn.example.com/my/bucket'
    }
  }
};

When the app is deployed, the image will be broken, because it should have been written like so:

<script>
  import { assets } from '$app/paths';
</script>

<img alt="potato" src="${assets}/images/potato.jpg">

But because assets === '/.' during development, the wrong version is indistinguishable from the right version.

Not totally sure what the right solution is. We don't want to force people to always use ${assets} in the case where they don't use the paths config, but it causes confusing problems if it's absent when there is a paths config. Maybe if there's a paths config, assets should be set during development to something like /_static_assets to force you to use the prefix, but otherwise it should behave as it currently does?

@Rich-Harris
Copy link
Member Author

Rich-Harris commented Jan 19, 2021

Relatedly, it appears that prerendered pages have the wrong assets path (i.e. the empty string) reflected in the HTML — the correct path doesn't come in until JS runs

@Rich-Harris Rich-Harris mentioned this issue Mar 4, 2021
@Rich-Harris Rich-Harris added this to the 1.0 milestone Mar 5, 2021
@Rich-Harris Rich-Harris modified the milestones: 1.0, post-1.0 May 1, 2021
@benmccann benmccann added the feature request New feature or request label Jul 15, 2021
@Rich-Harris
Copy link
Member Author

This can be closed — in dev, assets is replaced with _svelte_kit_assets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants