/
index.html
228 lines (175 loc) · 6.85 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<h1>Optimize Deps</h1>
<h2>CommonJS w/ named imports (react)</h2>
<div class="cjs"></div>
<h2>CommonJS w/ named imports (phoenix)</h2>
<div class="cjs-phoenix">fail</div>
<h2>CommonJS w/ default export (clipboard)</h2>
<div class="cjs-clipboard">fail</div>
<script type="module" src="./cjs.js"></script>
<h2>CommonJS dynamic import default + named (react)</h2>
<div class="cjs-dynamic"></div>
<h2>CommonJS dynamic import named (phoenix)</h2>
<div class="cjs-dynamic-phoenix"></div>
<h2>CommonJS dynamic import default (clipboard)</h2>
<div class="cjs-dynamic-clipboard"></div>
<h2>CommonJS dynamic import default (dep-cjs-compiled-from-esm)</h2>
<div class="cjs-dynamic-dep-cjs-compiled-from-esm"></div>
<h2>CommonJS dynamic import default (dep-cjs-compiled-from-cjs)</h2>
<div class="cjs-dynamic-dep-cjs-compiled-from-cjs"></div>
<script type="module" src="./cjs-dynamic.js"></script>
<h2>Dedupe (dep in linked & optimized package)</h2>
<div class="dedupe"></div>
<script type="module" src="./dedupe.js"></script>
<h2>CommonJS w/ browser field mapping (axios)</h2>
<div>This should show pong: <span class="cjs-browser-field"></span></div>
<h2>CommonJS w/ bare id browser field mapping</h2>
<div>This should show pong: <span class="cjs-browser-field-bare"></span></div>
<h2>Detecting linked src package and optimizing its deps (lodash-es)</h2>
<div>This should show fooBarBaz: <span class="deps-linked"></span></div>
<h2>Optimizing force included dep even when it's linked</h2>
<div class="force-include"></div>
<h2>Dep with CSS</h2>
<div class="dep-linked-include">This should be red</div>
<h2>CJS Dep with CSS</h2>
<div class="cjs-with-assets">This should be blue</div>
<h2>import * as ...</h2>
<div class="import-star"></div>
<h2>Import from dependency with process.env.NODE_ENV</h2>
<div class="node-env"></div>
<h2>Import from dependency with .notjs files</h2>
<div class="not-js"></div>
<h2>
Import from dependency which uses relative path which needs to be resolved by
main field
</h2>
<div class="relative-to-main"></div>
<h2>Import from dependency with dynamic import</h2>
<div class="dep-with-dynamic-import"></div>
<h2>Import from dependency with optional peer dep</h2>
<div class="dep-with-optional-peer-dep"></div>
<h2>Externalize known non-js files in optimize included dep</h2>
<div class="externalize-known-non-js"></div>
<h2>Vue & Vuex</h2>
<div class="vue"></div>
<h2>Dep with changes from esbuild plugin</h2>
<div>This should show a greeting: <span class="esbuild-plugin"></span></div>
<h2>Dep from hidden dir</h2>
<div>This should show hello!: <span class="hidden-dir"></span></div>
<h2>Nested include</h2>
<div>Module path: <span class="nested-include"></span></div>
<h2>Alias with colon</h2>
<div>URL: <span class="url"></span></div>
<h2>Reused variable names</h2>
<div>This should show reused: <span class="reused-variable-names"></span></div>
<h2>Flatten Id</h2>
<div class="clonedeep-slash"></div>
<div class="clonedeep-dot"></div>
<h2>Non Optimized Module isn't duplicated</h2>
<div class="non-optimized-module-is-not-duplicated"></div>
<script>
function text(el, text) {
document.querySelector(el).textContent = text
}
</script>
<script type="module">
// test dep detection in globbed files
const globbed = import.meta.glob('./glob/*.js', { eager: true })
import cjsBrowerFieldBare from '@vitejs/test-dep-cjs-browser-field-bare'
text('.cjs-browser-field-bare', cjsBrowerFieldBare)
import { camelCase } from '@vitejs/test-dep-linked'
text('.deps-linked', camelCase('foo-bar-baz'))
import { msg, VueSFC } from '@vitejs/test-dep-linked-include'
text('.force-include', msg)
text('.externalize-known-non-js', VueSFC.render())
import * as linked from '@vitejs/test-dep-linked-include'
const keys = Object.keys(linked)
if (keys.length) {
text('.import-star', `[success] ${keys.join(', ')}`)
}
import '@vitejs/test-dep-cjs-with-assets'
import { env } from '@vitejs/test-dep-node-env'
text('.node-env', env)
import { notjsValue } from '@vitejs/test-dep-not-js'
text('.not-js', notjsValue)
import foo from '@vitejs/test-dep-relative-to-main/entry'
text('.relative-to-main', foo)
import { lazyFoo } from '@vitejs/test-dep-with-dynamic-import'
lazyFoo().then((foo) => {
text('.dep-with-dynamic-import', foo)
})
import { createApp } from 'vue'
import { createStore } from 'vuex'
if (typeof createApp === 'function' && typeof createStore === 'function') {
text('.vue', '[success]')
}
import { hello } from '@vitejs/test-dep-esbuild-plugin-transform'
text('.esbuild-plugin', hello())
import { greeting } from './.hidden-dir/foo.js'
text('.hidden-dir', greeting)
import { nestedInclude } from '@vitejs/test-nested-exclude'
text('.nested-include', nestedInclude)
import { parse } from 'node:url'
text('.url', parse('https://vitejs.dev').hostname)
import './index.astro'
// All these imports should end up resolved to the same URL (same ?v= injected on them)
import { add as addFromDirectAbsolutePath } from '/node_modules/@vitejs/test-dep-non-optimized/index.js'
import { add as addFromDirectRelativePath } from './node_modules/@vitejs/test-dep-non-optimized/index.js'
import { get as getFromBareImport } from '@vitejs/test-dep-non-optimized'
addFromDirectAbsolutePath('from-absolute-path')
addFromDirectRelativePath('from-relative-path')
text(
'.non-optimized-module-is-not-duplicated',
getFromBareImport().join(', '),
)
</script>
<script type="module">
const reusedName = 1
</script>
<script type="module">
const reusedName = 'reused'
text('.reused-variable-names', reusedName)
</script>
<script type="module">
import {
callItself,
callPeerDep,
} from '@vitejs/test-dep-with-optional-peer-dep'
text('.dep-with-optional-peer-dep', callItself())
// expect error as optional peer dep not installed
callPeerDep()
</script>
<script type="module">
// should error on builtin modules (named import)
// no node: protocol intentionally
import { Buffer } from 'buffer'
// named imports error immediately
</script>
<script type="module">
// should error on builtin modules (default import)
// no node: protocol intentionally
import cp from 'child_process'
// must access property to error
if (import.meta.env.DEV) {
cp.execSync()
}
</script>
<script type="module">
// should error on builtin modules from dep
import { read } from '@vitejs/test-dep-with-builtin-module-esm'
if (import.meta.env.DEV) {
read()
}
</script>
<script type="module">
// should error on builtin modules from dep
import { read } from '@vitejs/test-dep-with-builtin-module-cjs'
if (import.meta.env.DEV) {
read()
}
</script>
<script type="module">
import cloneDeepSlash from 'lodash/cloneDeep'
import cloneDeepDot from 'lodash.clonedeep'
text('.clonedeep-slash', cloneDeepSlash({ name: 'clonedeep-slash' }).name)
text('.clonedeep-dot', cloneDeepDot({ name: 'clonedeep-dot' }).name)
</script>