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

feat: support preloading also on legacy bundle #9920

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d4db5c9
feat: support preloading also in legacy bundle
Tal500 Aug 30, 2022
03d282e
chore: describe the `parseImportsSystemJS` function better
Tal500 Aug 31, 2022
06e69a8
test: ignoring code file for testing in prettier
Tal500 Aug 31, 2022
eced9b1
chore: adapt the code to work also in Node 12
Tal500 Aug 31, 2022
a413bc0
chore: test a change in the code
Tal500 Sep 1, 2022
2dc09b4
revert: chore: test a change in the code
Tal500 Sep 1, 2022
59fd103
chore: merge branch 'preload-on-system-format' of github.com:Tal500/v…
Tal500 Sep 1, 2022
96780a1
chore: fix revert issues
Tal500 Sep 1, 2022
6c38aa1
fix: fix the css regexp
Tal500 Sep 2, 2022
02995a1
fix: return the format to `module.import` in regex
Tal500 Sep 4, 2022
4b2b1d1
fix: and simplify the RE in `parseImportsSystemJS`
Tal500 Sep 4, 2022
900960b
test: more test snippets for `parseImportsSystemJS`
Tal500 Sep 4, 2022
d579efa
fix: safer detection of import regexp for empty css's
Tal500 Sep 4, 2022
9e04a5c
chore: omit the obsolete css inlining on legacy
Tal500 Sep 4, 2022
e6361ff
test: fix line ending issues while reading, and update the snapshot
Tal500 Sep 4, 2022
5e1ba19
test: (hopefully) fix line ending issues
Tal500 Sep 4, 2022
50627d2
test: and code files for testing to lint ignore
Tal500 Sep 4, 2022
e075dac
feat: better check on seeing whether the asset path was already loaded
Tal500 Sep 4, 2022
e567b21
fix: a much safer way to load CSS on legacy, while try to save perfor…
Tal500 Sep 4, 2022
0957a50
chore: fixing the `@ts-ignore` location (fighting with lint)
Tal500 Sep 4, 2022
6fbeb25
fix: linting issues
Tal500 Sep 4, 2022
a7501c2
feat: conditional waiting in preloading
Tal500 Sep 4, 2022
6bdb4e4
fix: make sure to have the full dep path
Tal500 Sep 4, 2022
40e4da0
fix: try to break also when paths are simply equal
Tal500 Sep 4, 2022
e72c090
chore: remove full dep equlity optimization for checking tests
Tal500 Sep 4, 2022
8298666
chore: simplify the code by removing the xhr request and thanks to th…
Tal500 Sep 5, 2022
6dbe676
chore: minor style improvement
Tal500 Sep 5, 2022
e578475
fix: add and use `analyzeSystemRegisteration` to handle parameter nam…
Tal500 Sep 5, 2022
2fd8eaf
build: change the dir to ignore on eslint
Tal500 Sep 5, 2022
8f68cdf
chore: simplify the code
Tal500 Sep 5, 2022
6923be3
fix: copy the suggested code from #9970
Tal500 Sep 10, 2022
94908e1
chore: fix typo
Tal500 Sep 10, 2022
1f05b29
chore: omit the fix for double stylesheets loading
Tal500 Sep 18, 2022
3c6240b
Merge branch 'main' into preload-on-system-format
Tal500 Sep 23, 2022
22dd608
Merge branch 'vitejs:main' into preload-on-system-format
Tal500 Sep 23, 2022
69d62a7
Merge branch 'main' into preload-on-system-format
Tal500 Sep 24, 2022
d5c9469
chore: Merge branch 'main' into preload-on-system-format
Tal500 Sep 28, 2022
f153ff2
fix: return css inlining only for library mode
Tal500 Sep 28, 2022
4b8a587
Merge branch 'main' into preload-on-system-format
Tal500 Oct 1, 2022
a722090
chore: Merge branch 'main' into preload-on-system-format
Tal500 Oct 19, 2022
6d4d82e
fix: give empty list of systemJS dynamic import, if the `moduleParam`…
Tal500 Oct 19, 2022
37e43a7
chore: merge branch 'main' into preload-on-system-format
Tal500 Nov 9, 2022
3d93a9f
refactor: cancel many regexp analysis, and use SystemJS `instantiate`…
Tal500 Nov 14, 2022
998ed72
chore: merge branch 'main' into preload-on-system-format
Tal500 Dec 11, 2022
ee90f4a
Merge branch 'main' into preload-on-system-format
Tal500 Jan 4, 2023
06f4657
chore: fix the `@ts-ignore` issue on CI
Tal500 Jan 4, 2023
44a4515
Merge branch 'main' into preload-on-system-format
Tal500 Feb 13, 2023
df949be
chore: add the non-nullish ! to "chunk.viteMetadata"
Tal500 Feb 13, 2023
1310ac0
Merge branch 'main' into pr/9920
sapphi-red Mar 13, 2023
3a3b6bc
Merge branch 'main' into pr/9920
sapphi-red Jun 22, 2023
896822a
fix: inline CSS in non-lib mode if css.codeSplit is false
sapphi-red Jun 22, 2023
1509a97
refactor: revert rename preloadMethod
sapphi-red Jun 22, 2023
211f4a7
test: test nested dynamic import
sapphi-red Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist
playground-temp
temp

packages/vite/src/node/__tests__/test-input/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pnpm-workspace.yaml
playground/tsconfig-json-load-error/has-error/tsconfig.json
playground/html/invalid.html
playground/worker/classic-worker.js
packages/vite/src/node/__tests__/test-input/
30 changes: 30 additions & 0 deletions packages/vite/src/node/__tests__/__snapshots__/utils.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Vitest Snapshot v1

exports[`analyzeSystemRegisteration > hello 1`] = `undefined`;

exports[`analyzeSystemRegisteration > minified 1`] = `
{
"chunkListCode": "[\\"./chunks/index-legacy-60db70ad.js\\",\\"./chunks/singletons-legacy-a9d19225.js\\"]",
"exportParam": "n",
"moduleParam": "o",
"paramsCode": "(n,o)",
}
`;

exports[`analyzeSystemRegisteration > svelte-legacy-part 1`] = `
{
"chunkListCode": "['./chunks/index-legacy-60db70ad.js', './chunks/singletons-legacy-4fba2acb.js']",
"exportParam": "exports",
"moduleParam": "module",
"paramsCode": "(exports, module)",
}
`;

exports[`analyzeSystemRegisteration > vue-legacy-part 1`] = `
{
"chunkListCode": "[]",
"exportParam": "exports",
"moduleParam": "module",
"paramsCode": "(exports, module)",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Vitest Snapshot v1

exports[`parse import system js > hello 1`] = `[]`;

exports[`parse import system js > minified 1`] = `
[
{
"a": -1,
"d": 203,
"e": 234,
"n": "./chunks/0-legacy-dd26244b.js",
"s": 205,
"se": 236,
"ss": 195,
},
{
"a": -1,
"d": 318,
"e": 349,
"n": "./chunks/1-legacy-3bf807d6.js",
"s": 320,
"se": 351,
"ss": 310,
},
{
"a": -1,
"d": 433,
"e": 464,
"n": "./chunks/2-legacy-d3251462.js",
"s": 435,
"se": 466,
"ss": 425,
},
{
"a": -1,
"d": 548,
"e": 579,
"n": "./chunks/3-legacy-4e1e80dc.js",
"s": 550,
"se": 581,
"ss": 540,
},
{
"a": -1,
"d": 663,
"e": 694,
"n": "./chunks/4-legacy-7e73478a.js",
"s": 665,
"se": 696,
"ss": 655,
},
]
`;

exports[`parse import system js > svelte-legacy-part 1`] = `
[
{
"a": -1,
"d": 256,
"e": 287,
"n": "./chunks/0-legacy-c5b945f8.js",
"s": 258,
"se": 290,
"ss": 243,
},
{
"a": -1,
"d": 406,
"e": 437,
"n": "./chunks/1-legacy-b7de93b3.js",
"s": 408,
"se": 440,
"ss": 393,
},
{
"a": -1,
"d": 563,
"e": 594,
"n": "./chunks/2-legacy-c3551ff3.js",
"s": 565,
"se": 597,
"ss": 550,
},
{
"a": -1,
"d": 719,
"e": 750,
"n": "./chunks/3-legacy-9a5e7ba5.js",
"s": 721,
"se": 753,
"ss": 706,
},
{
"a": -1,
"d": 876,
"e": 906,
"n": "/chunks/4-legacy-5f612355.js",
"s": 878,
"se": 909,
"ss": 863,
},
]
`;

exports[`parse import system js > vue-legacy-part 1`] = `
[
{
"a": -1,
"d": 194,
"e": 223,
"n": "./module-legacy.de1a4764.js",
"s": 196,
"se": 225,
"ss": 181,
},
]
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { parseImportsSystemJS } from '../../../plugins/importAnalysisBuild'

const __dirname = resolve(fileURLToPath(import.meta.url), '..')

const readInputFile = (filename: string) =>
readFileSync(resolve(__dirname, '../../test-input/system-format', filename), {
encoding: 'utf8',
flag: 'r'
})

const snippets = ['hello', 'svelte-legacy-part', 'vue-legacy-part', 'minified']

describe('parse import system js', () => {
snippets.forEach((snippet) => {
it(snippet, () => {
expect(
parseImportsSystemJS(readInputFile(`${snippet}.js`))
).toMatchSnapshot()
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function hello() {
return 'hello'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function bla_bla() {}

System.register(["./chunks/index-legacy-60db70ad.js","./chunks/singletons-legacy-a9d19225.js"],(function(n,o){"use strict";

var _t=[function(){return Z((function(){return o.import("./chunks/0-legacy-dd26244b.js")}),"__VITE_PRELOAD__",o.meta.url)},function(){return Z((function(){return o.import("./chunks/1-legacy-3bf807d6.js")}),"__VITE_PRELOAD__",o.meta.url)},function(){return Z((function(){return o.import("./chunks/2-legacy-d3251462.js")}),"__VITE_PRELOAD__",o.meta.url)},function(){return Z((function(){return o.import("./chunks/3-legacy-4e1e80dc.js")}),"__VITE_PRELOAD__",o.meta.url)},function(){return Z((function(){return o.import("./chunks/4-legacy-7e73478a.js")}),"__VITE_PRELOAD__",o.meta.url)}]

}))
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
System.register(['./chunks/index-legacy-60db70ad.js', './chunks/singletons-legacy-4fba2acb.js'], function (exports, module) {
'use strict';

const __vitePreload = 0

var nodes = [function () {
return __vitePreload(function () {
return module.import('./chunks/0-legacy-c5b945f8.js');
}, "__VITE_PRELOAD__", module.meta.url);
}, function () {
return __vitePreload(function () { return module.import('./chunks/1-legacy-b7de93b3.js');
},"__VITE_PRELOAD__", module.meta.url);
}, function () {
return __vitePreload(function () {
return module.import("./chunks/2-legacy-c3551ff3.js");
}, "__VITE_PRELOAD__", module.meta.url);
}, function () {
return __vitePreload(function () {
return module.import('./chunks/3-legacy-9a5e7ba5.js'); }, "__VITE_PRELOAD__", module.meta.url);
}, function () {
return __vitePreload(function () {
return module.import("/chunks/4-legacy-5f612355.js");}, "__VITE_PRELOAD__" , module.meta.url);
}];

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
System.register([], function (exports, module) {
'use strict';

const _sfc_main = defineComponent({
components: {
module: defineAsyncComponent(() => __vitePreload(() => module.import('./module-legacy.de1a4764.js'), "__VITE_PRELOAD__", module.meta.url))
},

setup() {
return {
css
};
}

});

})
29 changes: 29 additions & 0 deletions packages/vite/src/node/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, test } from 'vitest'
import {
analyzeSystemRegisteration,
asyncFlatten,
getHash,
getLocalhostAddressIfDiffersFromDNS,
Expand All @@ -9,6 +13,21 @@ import {
resolveHostname
} from '../utils'

const __dirname = resolve(fileURLToPath(import.meta.url), '..')

const readInputFile = (filename: string) =>
readFileSync(resolve(__dirname, 'test-input/system-format', filename), {
encoding: 'utf8',
flag: 'r'
})

const system_format_snippets = [
'hello',
'svelte-legacy-part',
'vue-legacy-part',
'minified'
]

describe('injectQuery', () => {
if (isWindows) {
// this test will work incorrectly on unix systems
Expand Down Expand Up @@ -177,3 +196,13 @@ describe('asyncFlatten', () => {
expect(arr).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
})
})

describe('analyzeSystemRegisteration', () => {
Tal500 marked this conversation as resolved.
Show resolved Hide resolved
system_format_snippets.forEach((snippet) => {
test(snippet, () => {
expect(
analyzeSystemRegisteration(readInputFile(`${snippet}.js`))
).toMatchSnapshot()
})
})
})