Skip to content

2697: add base and asset transform to html template 🦎 #3088

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/cuddly-lemons-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@sveltejs/kit': patch
---

# Add base and asset transform to html template

- `%svelte.assets%` is the placeholder for `config.paths.assets`
- `%svelte.base%` is the placeholder for `config.paths.base`
3 changes: 3 additions & 0 deletions documentation/docs/14-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ An object containing zero or more of the following `string` values:

- `assets` — an absolute path that your app's files are served from. This is useful if your files are served from a storage bucket of some kind
- `base` — a root-relative path that must start, but not end with `/` (e.g. `/base-path`). This specifies where your app is served from and allows the app to live on a non-root path
- the specified paths will be available through a placeholder in your `.html` template.
- `%svelte.assets%` is the placeholder for `config.paths.assets`
- `%svelte.base%` is the placeholder for `config.paths.base`

### prerender

Expand Down
2 changes: 1 addition & 1 deletion documentation/migrating/03-project-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Most imports from `@sapper/service-worker` have equivalents in [`$service-worker

The `src/template.html` file should be renamed `src/app.html`.

Remove `%sapper.base%`, `%sapper.scripts%` and `%sapper.styles%`. Replace `%sapper.head%` with `%svelte.head%` and `%sapper.html%` with `%svelte.body%`.
Remove `%sapper.scripts%` and `%sapper.styles%`. Replace `%sapper.head%` with `%svelte.head%`, `%sapper.base%` with `%svelte.base%` and `%sapper.html%` with `%svelte.body%`.

The `<div id="sapper">` is no longer necessary, though you can continue mounting the app to a wrapper element by specifying it with the [`target`](/docs#configuration-target) config option.

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ async function build_server(
import * as user_hooks from ${s(app_relative(hooks_file))};

const template = ({ head, body }) => ${s(fs.readFileSync(config.kit.files.template, 'utf-8'))
.replace(/%svelte.base%/g, config.kit.paths.base)
.replace(/%svelte.assets%/g, config.kit.paths.assets)
.replace('%svelte.head%', '" + head + "')
.replace('%svelte.body%', '" + body + "')};

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ async function create_plugin(config, dir, cwd, get_manifest) {
template: ({ head, body }) => {
let rendered = fs
.readFileSync(config.kit.files.template, 'utf8')
.replace(/%svelte.base%/g, config.kit.paths.base)
.replace(/%svelte.assets%/g, config.kit.paths.assets)
.replace('%svelte.head%', () => head)
.replace('%svelte.body%', () => body);

Expand Down