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

[Nuxt Integration] Return dynamicDeps in transformRequest #4898

Closed
4 tasks done
antfu opened this issue Sep 10, 2021 · 0 comments
Closed
4 tasks done

[Nuxt Integration] Return dynamicDeps in transformRequest #4898

antfu opened this issue Sep 10, 2021 · 0 comments
Labels
enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@antfu
Copy link
Member

antfu commented Sep 10, 2021

Clear and concise description of the problem

In Nuxt, we are trying to use Vite Server for generating the SSR bundle on-demand instead of build with watcher - to align with the client behavior and get the perfance juice. We use a custom script with server.transformRequest to construct the bundle, currently we are facing an problem that dynamic depdenencies are not included in the deps array of the transform result.

Related: nuxt/vite#201 (comment)

Suggested solution

Return dynamicDeps list for transformRequest

const {
  code,
  deps,
  dynamicDeps,
} = await server.transformRequest('id')

Alternative

No response

Additional context

Current workaround:

function scanDynamicDeps (code: string) {
  return Array.from(code.matchAll(/__vite_ssr_dynamic_import__\(['"](.+?)['"]\)/g)).map(m => m[1])
}

const res = await transformRequest(viteServer, id)
// Vite does not include dynamic deps in `res.deps`, we manually scan for it
const dynamicDeps = scanDynamicDeps(res.code)
const deps = uniq([...res.deps, ...dynamicDeps])

Validations

@antfu antfu added enhancement: pending triage enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) and removed enhancement: pending triage labels Sep 10, 2021
antfu added a commit to antfu/vite that referenced this issue Sep 13, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

No branches or pull requests

1 participant