You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2da0e36
Browse filesBrowse the repository at this point in the historyBrowse files
feat(vite)!: serve dynamic imports as Vite writes them
The runtimes resolve relative and root-relative specifiers of a module loaded over HTTP against that module's URL, static and dynamic, with the query kept (NativeScript/ios#586; Android 9.1.x). The dev server no longer writes its origin into served modules, so their bodies, ETags and cache headers no longer depend on it, and non-literal relative imports work. Runtime builtins are still restored in responses.
The HMR client's own update import stays absolute: Vite's import analysis wraps it in injectQuery, which would add `import` to a root-relative URL and change the module's identity.
BREAKING CHANGE: on iOS and visionOS, lazy imports under Vite HMR need a runtime with NativeScript/ios#586.
it('prefixes the origin to root-relative literal dynamic imports, keeping quotes and query',()=>{
9
-
constcode=`const a = () => import('/src/lazy.ts?t=1700000000000');\nconst b = () => import("/@fs/repo/x.js");\n`;
10
-
expect(rewriteDeviceImports(code,`${ORIGIN}/`)).toBe(`const a = () => import('${ORIGIN}/src/lazy.ts?t=1700000000000');\nconst b = () => import("${ORIGIN}/@fs/repo/x.js");\n`);
11
-
});
12
-
13
-
it('leaves static imports, non-literal, relative, protocol-relative and absolute specifiers alone',()=>{
14
-
constcode=`import { a } from "/src/a.ts";\nexport * from '/src/b.ts';\nimport('./rel.js');\nimport('//cdn/x.js');\nimport('https://cdn/x.js');\nimport(name);\nimport(__vite__injectQuery(u, 'import'));\nconst u = import.meta.url;`;
it('leaves every specifier but a runtime builtin as Vite wrote it',()=>{
7
+
constcode=`import { a } from "/src/a.ts";\nexport * from '/src/b.ts';\nimport('/src/lazy.ts?t=1700000000000');\nimport("/@fs/repo/x.js");\nimport('./rel.js');\nimport('//cdn/x.js');\nimport('https://cdn/x.js');\nimport("/@id/some-bare");\nimport(name);\nimport(__vite__injectQuery(u, 'import'));`;
8
+
expect(rewriteDeviceImports(code)).toBe(code);
16
9
});
17
10
18
11
it('restores runtime builtins Vite serves under /@id/, static and dynamic',()=>{
19
12
constcode=`import * as m from "/@id/ns:module";\nexport { x } from '/@id/ns:util';\nconst h = () => import('/@id/ns:module');\nimport "/@id/__x00__virtual:ns-dev-boot";\nimport "/@id/some-bare";\n`;
20
-
expect(rewriteDeviceImports(code,ORIGIN)).toBe(`import * as m from "ns:module";\nexport { x } from 'ns:util';\nconst h = () => import('ns:module');\nimport "/@id/__x00__virtual:ns-dev-boot";\nimport "/@id/some-bare";\n`);
13
+
expect(rewriteDeviceImports(code)).toBe(`import * as m from "ns:module";\nexport { x } from 'ns:util';\nconst h = () => import('ns:module');\nimport "/@id/__x00__virtual:ns-dev-boot";\nimport "/@id/some-bare";\n`);
21
14
});
22
15
23
16
it('handles minified code and returns unparsable code unchanged',()=>{
0 commit comments