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

[Feature]: Inline async JS chunks when using inlineScripts: true #3240

Closed
zardoy opened this issue Aug 18, 2024 · 4 comments
Closed

[Feature]: Inline async JS chunks when using inlineScripts: true #3240

zardoy opened this issue Aug 18, 2024 · 4 comments

Comments

@zardoy
Copy link

zardoy commented Aug 18, 2024

What problem does this feature solve?

Hi! I want to create a single-file HTML file so everything is inline into one HTLM file. As far as I can say everything works good (all assets & styles are inlined without any problems), but not async js chunks. Maybe it's just docs, but the docs of inlineScript say:

Note that, with this option on, the scripts files will no longer be written in dist directory, they will only exist inside the HTML file instead.

Howerver when importing web workers and other modules with import('...') it always creates a second JS file along the HTML file like so:

File                                       Size       Gzipped    
  dist/static/js/async/js/588.487dabea.js    0.34 kB    0.23 kB
  dist/index.html                            13.1 kB    4.8 kB

What does the proposed API look like?

I cant say anything of enabling this by default, but there should be a way to actually inline all the scripts into HTML (this feature is actually useful). For example add a new flag/option config into inlineScripts object config.

Tasks

No tasks being tracked yet.
@zardoy
Copy link
Author

zardoy commented Aug 18, 2024

About the web worker part: it seems rsbuild doesn't support bundling it. I'm coming from Vite which supports these imports:

https://v3.vitejs.dev/guide/features.html#import-with-query-suffixes

import MyWorker from './worker?worker&inline'

const worker = new MyWorker()

@zardoy zardoy closed this as completed Aug 18, 2024
@zardoy zardoy reopened this Aug 18, 2024
@chenjiahan
Copy link
Member

Rspack provides a module.parser.javascript.dynamicImportMode option to avoid generating async chunks of dynamic imports:

export default {
  output: {
    inlineScripts: true,
  },
  tools: {
    rspack: {
      module: {
        parser: {
          javascript: {
            dynamicImportMode: 'eager',
          },
        },
      },
    },
  },
};

@zardoy
Copy link
Author

zardoy commented Aug 18, 2024

Thanks a lot for a quick response and improving the docs by a lot!
I'm still struggling with inlining webworkers into HTML (and I think it's worth mentioning webworker part in the Vite migration guide), but that's the matter of another issue.

@zardoy zardoy closed this as completed Aug 18, 2024
@chenjiahan
Copy link
Member

Yeah webworker inlining is another issue and we should provide a guide for it

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

No branches or pull requests

2 participants