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

Build output includes unused JS with static adapter #1371

Closed
matthew-ia opened this issue May 6, 2021 · 5 comments
Closed

Build output includes unused JS with static adapter #1371

matthew-ia opened this issue May 6, 2021 · 5 comments
Labels
feature / enhancement New feature or request

Comments

@matthew-ia
Copy link

Describe the bug
Using adapter-static and the config options: hydrate: false and router: false—and no JS within any components—.js files that aren't used are still output in ./build when running npm run build.

E.g. with this svelte.config.js:

import adapter from '@sveltejs/adapter-static';
const config = {
  kit: {
    target: '#svelte',
    hydrate: false,
    router: false,
    adapter: adapter(),
  }
};

I get an output index.html that includes no link or script tags (as expected), but there are output .js files such as ./build/start-*.js and .build/pages/index.svelte-*.js.

To Reproduce

  • Install "Skeleton" project using SvelteKit
  • Install adapter-static and add it tosvelte.config.js
  • set hydrate: false and router: false in svelte.config.js
  • run npm run build

Here's a reproduction example repo with the above configuration: https://github.com/matthew-ia/svelte-static-mvp

Expected behavior
Any files that aren't necessary for the build should not be included within ./build

Adapter: adaper-static

Severity
Low – while this behavior was confusing—I was under the impression the site needed all that JS which led me down a rabbit hole trying to figure out how to remove it—the output index.html is still correct, and the use-case for having a 100% static, no-JS output is likely pretty niche.

@babichjacob babichjacob added this to the whenever milestone May 14, 2021
@babichjacob babichjacob added the feature / enhancement New feature or request label Jun 12, 2021
@quentincaffeino
Copy link

For this purpose I have this line in my build pipeline: find ./build -name "*.js" | xargs rm
But having it output no unused assets would be definitely nice.

@ignatiusmb ignatiusmb removed this from the whenever milestone Aug 22, 2021
@ignatiusmb
Copy link
Member

The user would still get a "100% static, no-JS" page as you mentioned, all those unused files would only exists in the server and won't be shipped to the user.

But, what happens when some of the pages used it, would we need to scan for all the generated html files and see if there's any JS files that aren't linked or used? I'm guessing this would increase the build time significantly, thus I'm not sure what our best approach should be here.

@ignatiusmb
Copy link
Member

This is applicable to all pages, prerendered without router and hydration. Also slightly related #1197

@benmccann
Copy link
Member

There's not really any harm in this and it's not straightforward to change, so I don't think we'd change this

@Sofahamster
Copy link

There's not really any harm

This isn't strictly true. The harm is that you can't really rsync deploy the build output because it needs to be fixed in a separate build step.

If I, the user, set csr to false, I expect that no JavaScript is produced. Everything else is a bug.

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

No branches or pull requests

6 participants