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

add paths: { base, assets } and appDir config #240

Merged
merged 6 commits into from
Dec 9, 2020
Merged

add paths: { base, assets } and appDir config #240

merged 6 commits into from
Dec 9, 2020

Conversation

Rich-Harris
Copy link
Member

Adds the paths option from #229 (comment)

@Rich-Harris
Copy link
Member Author

The design as things stand:

// svelte.config.js
module.exports = {
  kit: {
    paths: {
      base: '',
      assets: '',
    },
    appDir: '_app'
  }
};

paths.base is a root-relative pathname — if it is equal to /foo, then src/routes/bar.svelte equates to /foo/bar. paths.assets can be relative (in which case resolved against base, root-relative or absolute. They can be imported inside the app from $app/paths:

import { base, assets } from '$app/paths';

appDir is the directory that hashed JS/CSS/whatever chunks are written to. It must be a subdirectory of assets. It can't be imported from anywhere because there's no reason you'd want to do that.


This does introduce some new wrinkles. It doesn't make sense for adapter-static, for example, to put pre-rendered pages and assets in the same place if they're potentially on entirely different domains. But since in many cases that's exactly what you want, it needs to be configurable, so it probably needs to look something like this:

// svelte.config.js
module.exports = {
  kit: {
    adapter: ['@sveltejs/adapter-static', {
      // output everything to the same directory...
      pages: 'build',
      assets: 'build'
    }],
    paths: {
      // ...since there's no funny business with different domains:
      base: '',
      assets: '',
    }
  }
};
// svelte.config.js
module.exports = {
  kit: {
    adapter: ['@sveltejs/adapter-static', {
      // output assets to a separate directory...
      pages: 'build/pages',
      assets: 'build/assets'
    }],
    paths: {
      // ...so we can upload them to somewhere other than our website
      base: '',
      assets: 'https://cdn.example.com/buckets/xyz123',
    }
  }
};

Other adapters will likely have to accommodate these options somehow. For example what is adapter-node's responsibility viz static assets if paths.assets is an external URL?

@Rich-Harris Rich-Harris changed the title [WIP] add paths option add paths: { base, assets } and appDir config Dec 9, 2020
@Rich-Harris Rich-Harris merged commit d372a2a into master Dec 9, 2020
@Rich-Harris Rich-Harris deleted the paths branch December 9, 2020 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants