question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build an output that is usable from local disk (file:// URL)

See original GitHub issue

Is your feature request related to a problem? Please describe. Quite often i code tools which take some input (like a JSON file) and generate a HTML report out of it. This HTML report might be served by a server (e.g. Github Pages) but often just sits somewhere on the disk and should be openable/consumable from there (e.g. open file:///Users/x/projects/y/build/test/index.html).

Describe the solution you’d like From initial experiments (with adapter-static) I found 2 things I would need for the above to work which I failed to accomplish with svelte-kit so far:

  • Links/Includes (from index.html) need to be relative instead of absolute
    • paths/assets||base were quite resistant setting up anything relative
  • The JS field need to be in IIFE format (since module script imports will raise CORS issues)
    • vite.build: { lib: { name: "my-app", entry: "src/main.ts", formats: ["iife"] }} produced UMD and IIFE output formats are not supported for code-splitting builds

A solution would be to make the 2 things possible. Perfect would be a simple way to achieve that. Like an specialized adapter.

Describe alternatives you’ve considered Maybe what I’m trying to achieve is dump and using svelte-kit for such a thing doesn’t make much sense? Just stick to Svelte Classic ?

With Svelte Classic and Vite I can accomplish the above by tweaking vite.config.js in the following way:

  • Set base to '' (makes the links relative)
  • Configure IIEF format:
build: {
  lib: { name: "my-app", entry: "src/main.ts", formats: ["iife"] },
}
  • Move the index.html to public/ and add appropriate script and css includes

How important is this feature to you? This is the first thing I usually set up for the majority of apps I’m crafting.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:24
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
mattiashcommented, Feb 9, 2022

After a lot of tinkering I have managed to build a script that can take an html-file generated by adapter-static and inline all javascript in the file. It is very hacky and runs code in the browser to make the imports work, but it works for my use-case which is to build simple html-files with a bit of interactivity in them that I can send in an email without hosting them anywhere. Might be useful as inspiration for someone.

The trickiest part is that the only way I could use import was if the the module was added as a blob to the page. But adding it as a blob generates a new url for the module, which means that all import statements must be rewritten after the blob has been added.

https://github.com/mattiash/svelte-notebook/blob/master/util/inlinejs.cjs

1reaction
AlsDevShackcommented, Oct 11, 2021

Also hoping this can get added to sveltekit.

IMO This is essential for running native apps with svelte running in WebView as a GUI

Is there a workaround available?

I’d like to keep using SvelteKit for creating the full blown app with a server. But also need the SPA app to be run from file on client if no connection is available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

file URI scheme - Wikipedia
The file URI Scheme is a URI scheme defined in RFC 8089, typically used to retrieve files from within one's own computer. Previously...
Read more >
url - How to specify a local file within html using the file: scheme?
The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide...
Read more >
How to create url for an image which is on my computer hard ...
Right click on the image · open properties · Copy file location and file name · In your write html <img src='file_location/filename.file_format'> ·...
Read more >
Local Filesystem - Rclone
For consistencies sake one can also configure a remote of type local in the config file, and access the local filesystem using rclone...
Read more >
How to Create Symbolic Links: A Comprehensive Guide
A hard link is a synced copy of a file that directly refers to the ... Here are example outputs after creating the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found