vite 2.6.0-beta.0 → 2.6.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vite might be problematic. Click here for more details.
- package/CHANGELOG.md +66 -0
- package/LICENSE.md +161 -3011
- package/bin/vite.js +2 -1
- package/dist/node/chunks/{dep-91aa74e8.js → dep-1e0a75a8.js} +58 -32
- package/dist/node/chunks/dep-1e0a75a8.js.map +1 -0
- package/dist/node/chunks/{dep-e36486f6.js → dep-ac1b4bf9.js} +1 -1
- package/dist/node/chunks/dep-ac1b4bf9.js.map +1 -0
- package/dist/node/chunks/{dep-c7e510f9.js → dep-ba6b30a0.js} +27538 -4953
- package/dist/node/chunks/dep-ba6b30a0.js.map +1 -0
- package/dist/node/chunks/{dep-11213a75.js → dep-c4cf6e92.js} +19 -6
- package/dist/node/chunks/dep-c4cf6e92.js.map +1 -0
- package/dist/node/chunks/{dep-eb6ef720.js → dep-d574094c.js} +18 -5
- package/dist/node/chunks/dep-d574094c.js.map +1 -0
- package/dist/node/chunks/{dep-0d2f9464.js → dep-e39b05d6.js} +18 -5
- package/dist/node/chunks/dep-e39b05d6.js.map +1 -0
- package/dist/node/cli.js +60 -23992
- package/dist/node/cli.js.map +1 -1
- package/dist/node/index.d.ts +26 -8
- package/dist/node/index.js +18 -15
- package/dist/node/index.js.map +1 -1
- package/dist/node/terser.js +102 -55
- package/package.json +28 -13
- package/types/package.json +3 -0
- package/api-extractor.json +0 -54
- package/dist/node/chunks/dep-0d2f9464.js.map +0 -1
- package/dist/node/chunks/dep-11213a75.js.map +0 -1
- package/dist/node/chunks/dep-91aa74e8.js.map +0 -1
- package/dist/node/chunks/dep-c7e510f9.js.map +0 -1
- package/dist/node/chunks/dep-e36486f6.js.map +0 -1
- package/dist/node/chunks/dep-eb6ef720.js.map +0 -1
- package/dist/node/terser.js.map +0 -1
- package/rollup.config.js +0 -389
- package/scripts/patchTypes.js +0 -70
- package/src/node/__tests__/asset.spec.ts +0 -156
- package/src/node/__tests__/build.spec.ts +0 -67
- package/src/node/__tests__/config.spec.ts +0 -166
- package/src/node/__tests__/packages/name/package.json +0 -3
- package/src/node/__tests__/packages/noname/package.json +0 -1
- package/src/node/__tests__/plugins/css.spec.ts +0 -116
- package/src/node/__tests__/scan.spec.ts +0 -118
- package/src/node/__tests__/utils.spec.ts +0 -40
- package/src/node/build.ts +0 -783
- package/src/node/cli.ts +0 -239
- package/src/node/config.ts +0 -1033
- package/src/node/constants.ts +0 -87
- package/src/node/importGlob.ts +0 -173
- package/src/node/index.ts +0 -88
- package/src/node/logger.ts +0 -167
- package/src/node/optimizer/esbuildDepPlugin.ts +0 -216
- package/src/node/optimizer/index.ts +0 -410
- package/src/node/optimizer/registerMissing.ts +0 -102
- package/src/node/optimizer/scan.ts +0 -457
- package/src/node/plugin.ts +0 -138
- package/src/node/plugins/asset.ts +0 -365
- package/src/node/plugins/assetImportMetaUrl.ts +0 -99
- package/src/node/plugins/clientInjections.ts +0 -72
- package/src/node/plugins/css.ts +0 -1279
- package/src/node/plugins/dataUri.ts +0 -64
- package/src/node/plugins/define.ts +0 -107
- package/src/node/plugins/esbuild.ts +0 -280
- package/src/node/plugins/html.ts +0 -673
- package/src/node/plugins/importAnalysis.ts +0 -614
- package/src/node/plugins/importAnalysisBuild.ts +0 -334
- package/src/node/plugins/index.ts +0 -69
- package/src/node/plugins/json.ts +0 -75
- package/src/node/plugins/loadFallback.ts +0 -19
- package/src/node/plugins/manifest.ts +0 -123
- package/src/node/plugins/modulePreloadPolyfill.ts +0 -100
- package/src/node/plugins/preAlias.ts +0 -22
- package/src/node/plugins/reporter.ts +0 -244
- package/src/node/plugins/resolve.ts +0 -925
- package/src/node/plugins/terser.ts +0 -40
- package/src/node/plugins/wasm.ts +0 -72
- package/src/node/plugins/worker.ts +0 -117
- package/src/node/preview.ts +0 -82
- package/src/node/server/__tests__/fixtures/none/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/pnpm-workspace.yaml +0 -0
- package/src/node/server/__tests__/fixtures/yarn/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/yarn/package.json +0 -6
- package/src/node/server/__tests__/search-root.spec.ts +0 -31
- package/src/node/server/hmr.ts +0 -489
- package/src/node/server/http.ts +0 -198
- package/src/node/server/index.ts +0 -705
- package/src/node/server/middlewares/base.ts +0 -52
- package/src/node/server/middlewares/error.ts +0 -98
- package/src/node/server/middlewares/indexHtml.ts +0 -170
- package/src/node/server/middlewares/proxy.ts +0 -124
- package/src/node/server/middlewares/spaFallback.ts +0 -32
- package/src/node/server/middlewares/static.ts +0 -153
- package/src/node/server/middlewares/time.ts +0 -18
- package/src/node/server/middlewares/transform.ts +0 -196
- package/src/node/server/moduleGraph.ts +0 -200
- package/src/node/server/openBrowser.ts +0 -101
- package/src/node/server/pluginContainer.ts +0 -546
- package/src/node/server/searchRoot.ts +0 -70
- package/src/node/server/send.ts +0 -54
- package/src/node/server/sourcemap.ts +0 -54
- package/src/node/server/transformRequest.ts +0 -168
- package/src/node/server/ws.ts +0 -131
- package/src/node/ssr/__tests__/ssrTransform.spec.ts +0 -309
- package/src/node/ssr/ssrExternal.ts +0 -161
- package/src/node/ssr/ssrManifestPlugin.ts +0 -53
- package/src/node/ssr/ssrModuleLoader.ts +0 -214
- package/src/node/ssr/ssrStacktrace.ts +0 -75
- package/src/node/ssr/ssrTransform.ts +0 -452
- package/src/node/tsconfig.json +0 -14
- package/src/node/utils.ts +0 -565
- package/tsconfig.base.json +0 -11
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { ResolvedConfig } from '../config'
|
|
3
|
-
import { Plugin } from '../plugin'
|
|
4
|
-
import MagicString from 'magic-string'
|
|
5
|
-
import { ImportSpecifier, init, parse as parseImports } from 'es-module-lexer'
|
|
6
|
-
import { OutputChunk } from 'rollup'
|
|
7
|
-
import {
|
|
8
|
-
chunkToEmittedCssFileMap,
|
|
9
|
-
isCSSRequest,
|
|
10
|
-
removedPureCssFilesCache
|
|
11
|
-
} from './css'
|
|
12
|
-
import { transformImportGlob } from '../importGlob'
|
|
13
|
-
import { bareImportRE } from '../utils'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A flag for injected helpers. This flag will be set to `false` if the output
|
|
17
|
-
* target is not native es - so that injected helper logic can be conditionally
|
|
18
|
-
* dropped.
|
|
19
|
-
*/
|
|
20
|
-
export const isModernFlag = `__VITE_IS_MODERN__`
|
|
21
|
-
export const preloadMethod = `__vitePreload`
|
|
22
|
-
export const preloadMarker = `__VITE_PRELOAD__`
|
|
23
|
-
export const preloadBaseMarker = `__VITE_PRELOAD_BASE__`
|
|
24
|
-
|
|
25
|
-
const preloadHelperId = 'vite/preload-helper'
|
|
26
|
-
const preloadMarkerRE = new RegExp(`"${preloadMarker}"`, 'g')
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Helper for preloading CSS and direct imports of async chunks in parallel to
|
|
30
|
-
* the async chunk itself.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
function detectScriptRel() {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
const relList = document.createElement('link').relList
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
return relList && relList.supports && relList.supports('modulepreload')
|
|
38
|
-
? 'modulepreload'
|
|
39
|
-
: 'preload'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
declare const scriptRel: string
|
|
43
|
-
function preload(baseModule: () => Promise<{}>, deps?: string[]) {
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
if (!__VITE_IS_MODERN__ || !deps || deps.length === 0) {
|
|
46
|
-
return baseModule()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return Promise.all(
|
|
50
|
-
deps.map((dep) => {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
dep = `${base}${dep}`
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
if (dep in seen) return
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
seen[dep] = true
|
|
57
|
-
const isCss = dep.endsWith('.css')
|
|
58
|
-
const cssSelector = isCss ? '[rel="stylesheet"]' : ''
|
|
59
|
-
// @ts-ignore check if the file is already preloaded by SSR markup
|
|
60
|
-
if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
const link = document.createElement('link')
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
link.rel = isCss ? 'stylesheet' : scriptRel
|
|
67
|
-
if (!isCss) {
|
|
68
|
-
link.as = 'script'
|
|
69
|
-
link.crossOrigin = ''
|
|
70
|
-
}
|
|
71
|
-
link.href = dep
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
document.head.appendChild(link)
|
|
74
|
-
if (isCss) {
|
|
75
|
-
return new Promise((res, rej) => {
|
|
76
|
-
link.addEventListener('load', res)
|
|
77
|
-
link.addEventListener('error', rej)
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
).then(() => baseModule())
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Build only. During serve this is performed as part of ./importAnalysis.
|
|
86
|
-
*/
|
|
87
|
-
export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
|
|
88
|
-
const ssr = !!config.build.ssr
|
|
89
|
-
const insertPreload = !(ssr || !!config.build.lib)
|
|
90
|
-
|
|
91
|
-
const scriptRel = config.build.polyfillModulePreload
|
|
92
|
-
? `'modulepreload'`
|
|
93
|
-
: `(${detectScriptRel.toString()})()`
|
|
94
|
-
const preloadCode = `const scriptRel = ${scriptRel};const seen = {};const base = '${preloadBaseMarker}';export const ${preloadMethod} = ${preload.toString()}`
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
name: 'vite:import-analysis',
|
|
98
|
-
|
|
99
|
-
resolveId(id) {
|
|
100
|
-
if (id === preloadHelperId) {
|
|
101
|
-
return id
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
load(id) {
|
|
106
|
-
if (id === preloadHelperId) {
|
|
107
|
-
return preloadCode.replace(preloadBaseMarker, config.base)
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
async transform(source, importer) {
|
|
112
|
-
if (
|
|
113
|
-
importer.includes('node_modules') &&
|
|
114
|
-
!source.includes('import.meta.glob')
|
|
115
|
-
) {
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
await init
|
|
120
|
-
|
|
121
|
-
let imports: readonly ImportSpecifier[] = []
|
|
122
|
-
try {
|
|
123
|
-
imports = parseImports(source)[0]
|
|
124
|
-
} catch (e: any) {
|
|
125
|
-
this.error(e, e.idx)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!imports.length) {
|
|
129
|
-
return null
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
let s: MagicString | undefined
|
|
133
|
-
const str = () => s || (s = new MagicString(source))
|
|
134
|
-
let needPreloadHelper = false
|
|
135
|
-
|
|
136
|
-
for (let index = 0; index < imports.length; index++) {
|
|
137
|
-
const {
|
|
138
|
-
s: start,
|
|
139
|
-
e: end,
|
|
140
|
-
ss: expStart,
|
|
141
|
-
n: specifier,
|
|
142
|
-
d: dynamicIndex
|
|
143
|
-
} = imports[index]
|
|
144
|
-
|
|
145
|
-
// import.meta.glob
|
|
146
|
-
if (
|
|
147
|
-
source.slice(start, end) === 'import.meta' &&
|
|
148
|
-
source.slice(end, end + 5) === '.glob'
|
|
149
|
-
) {
|
|
150
|
-
const { importsString, exp, endIndex, isEager } =
|
|
151
|
-
await transformImportGlob(
|
|
152
|
-
source,
|
|
153
|
-
start,
|
|
154
|
-
importer,
|
|
155
|
-
index,
|
|
156
|
-
config.root,
|
|
157
|
-
undefined,
|
|
158
|
-
insertPreload
|
|
159
|
-
)
|
|
160
|
-
str().prepend(importsString)
|
|
161
|
-
str().overwrite(expStart, endIndex, exp)
|
|
162
|
-
if (!isEager) {
|
|
163
|
-
needPreloadHelper = true
|
|
164
|
-
}
|
|
165
|
-
continue
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (dynamicIndex > -1 && insertPreload) {
|
|
169
|
-
needPreloadHelper = true
|
|
170
|
-
const dynamicEnd = source.indexOf(`)`, end) + 1
|
|
171
|
-
const original = source.slice(dynamicIndex, dynamicEnd)
|
|
172
|
-
const replacement = `${preloadMethod}(() => ${original},${isModernFlag}?"${preloadMarker}":void 0)`
|
|
173
|
-
str().overwrite(dynamicIndex, dynamicEnd, replacement)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Differentiate CSS imports that use the default export from those that
|
|
177
|
-
// do not by injecting a ?used query - this allows us to avoid including
|
|
178
|
-
// the CSS string when unnecessary (esbuild has trouble treeshaking
|
|
179
|
-
// them)
|
|
180
|
-
if (
|
|
181
|
-
specifier &&
|
|
182
|
-
isCSSRequest(specifier) &&
|
|
183
|
-
source.slice(expStart, start).includes('from') &&
|
|
184
|
-
// edge case for package names ending with .css (e.g normalize.css)
|
|
185
|
-
!(bareImportRE.test(specifier) && !specifier.includes('/'))
|
|
186
|
-
) {
|
|
187
|
-
const url = specifier.replace(/\?|$/, (m) => `?used${m ? '&' : ''}`)
|
|
188
|
-
str().overwrite(start, end, dynamicIndex > -1 ? `'${url}'` : url)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (
|
|
193
|
-
needPreloadHelper &&
|
|
194
|
-
insertPreload &&
|
|
195
|
-
!source.includes(`const ${preloadMethod} =`)
|
|
196
|
-
) {
|
|
197
|
-
str().prepend(`import { ${preloadMethod} } from "${preloadHelperId}";`)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (s) {
|
|
201
|
-
return {
|
|
202
|
-
code: s.toString(),
|
|
203
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
renderChunk(code, _, { format }) {
|
|
209
|
-
// make sure we only perform the preload logic in modern builds.
|
|
210
|
-
if (code.indexOf(isModernFlag) > -1) {
|
|
211
|
-
const re = new RegExp(isModernFlag, 'g')
|
|
212
|
-
const isModern = String(format === 'es')
|
|
213
|
-
if (config.build.sourcemap) {
|
|
214
|
-
const s = new MagicString(code)
|
|
215
|
-
let match: RegExpExecArray | null
|
|
216
|
-
while ((match = re.exec(code))) {
|
|
217
|
-
s.overwrite(
|
|
218
|
-
match.index,
|
|
219
|
-
match.index + isModernFlag.length,
|
|
220
|
-
isModern
|
|
221
|
-
)
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
code: s.toString(),
|
|
225
|
-
map: s.generateMap({ hires: true })
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
return code.replace(re, isModern)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return null
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
generateBundle({ format }, bundle) {
|
|
235
|
-
if (format !== 'es' || ssr) {
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
for (const file in bundle) {
|
|
240
|
-
const chunk = bundle[file]
|
|
241
|
-
// can't use chunk.dynamicImports.length here since some modules e.g.
|
|
242
|
-
// dynamic import to constant json may get inlined.
|
|
243
|
-
if (chunk.type === 'chunk' && chunk.code.indexOf(preloadMarker) > -1) {
|
|
244
|
-
const code = chunk.code
|
|
245
|
-
let imports: ImportSpecifier[]
|
|
246
|
-
try {
|
|
247
|
-
imports = parseImports(code)[0].filter((i) => i.d > -1)
|
|
248
|
-
} catch (e: any) {
|
|
249
|
-
this.error(e, e.idx)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (imports.length) {
|
|
253
|
-
const s = new MagicString(code)
|
|
254
|
-
for (let index = 0; index < imports.length; index++) {
|
|
255
|
-
const { s: start, e: end, d: dynamicIndex } = imports[index]
|
|
256
|
-
// check the chunk being imported
|
|
257
|
-
const url = code.slice(start, end)
|
|
258
|
-
const deps: Set<string> = new Set()
|
|
259
|
-
let hasRemovedPureCssChunk = false
|
|
260
|
-
|
|
261
|
-
if (url[0] === `"` && url[url.length - 1] === `"`) {
|
|
262
|
-
const ownerFilename = chunk.fileName
|
|
263
|
-
// literal import - trace direct imports and add to deps
|
|
264
|
-
const analyzed: Set<string> = new Set<string>()
|
|
265
|
-
const addDeps = (filename: string) => {
|
|
266
|
-
if (filename === ownerFilename) return
|
|
267
|
-
if (analyzed.has(filename)) return
|
|
268
|
-
analyzed.add(filename)
|
|
269
|
-
const chunk = bundle[filename] as OutputChunk | undefined
|
|
270
|
-
if (chunk) {
|
|
271
|
-
deps.add(chunk.fileName)
|
|
272
|
-
const cssFiles = chunkToEmittedCssFileMap.get(chunk)
|
|
273
|
-
if (cssFiles) {
|
|
274
|
-
cssFiles.forEach((file) => {
|
|
275
|
-
deps.add(file)
|
|
276
|
-
})
|
|
277
|
-
}
|
|
278
|
-
chunk.imports.forEach(addDeps)
|
|
279
|
-
} else {
|
|
280
|
-
const removedPureCssFiles =
|
|
281
|
-
removedPureCssFilesCache.get(config)!
|
|
282
|
-
const chunk = removedPureCssFiles.get(filename)
|
|
283
|
-
if (chunk) {
|
|
284
|
-
const cssFiles = chunkToEmittedCssFileMap.get(chunk)
|
|
285
|
-
if (cssFiles && cssFiles.size > 0) {
|
|
286
|
-
cssFiles.forEach((file) => {
|
|
287
|
-
deps.add(file)
|
|
288
|
-
})
|
|
289
|
-
hasRemovedPureCssChunk = true
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
s.overwrite(dynamicIndex, end + 1, 'Promise.resolve({})')
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const normalizedFile = path.posix.join(
|
|
297
|
-
path.posix.dirname(chunk.fileName),
|
|
298
|
-
url.slice(1, -1)
|
|
299
|
-
)
|
|
300
|
-
addDeps(normalizedFile)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
let markPos = code.indexOf(preloadMarker, end)
|
|
304
|
-
// fix issue #3051
|
|
305
|
-
if (markPos === -1 && imports.length === 1) {
|
|
306
|
-
markPos = code.indexOf(preloadMarker)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (markPos > 0) {
|
|
310
|
-
s.overwrite(
|
|
311
|
-
markPos - 1,
|
|
312
|
-
markPos + preloadMarker.length + 1,
|
|
313
|
-
// the dep list includes the main chunk, so only need to
|
|
314
|
-
// preload when there are actual other deps.
|
|
315
|
-
deps.size > 1 ||
|
|
316
|
-
// main chunk is removed
|
|
317
|
-
(hasRemovedPureCssChunk && deps.size > 0)
|
|
318
|
-
? `[${[...deps].map((d) => JSON.stringify(d)).join(',')}]`
|
|
319
|
-
: `[]`
|
|
320
|
-
)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
chunk.code = s.toString()
|
|
324
|
-
// TODO source map
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// there may still be markers due to inlined dynamic imports, remove
|
|
328
|
-
// all the markers regardless
|
|
329
|
-
chunk.code = chunk.code.replace(preloadMarkerRE, 'void 0')
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ResolvedConfig } from '../config'
|
|
2
|
-
import { Plugin } from '../plugin'
|
|
3
|
-
import aliasPlugin from '@rollup/plugin-alias'
|
|
4
|
-
import { jsonPlugin } from './json'
|
|
5
|
-
import { resolvePlugin } from './resolve'
|
|
6
|
-
import { esbuildPlugin } from './esbuild'
|
|
7
|
-
import { importAnalysisPlugin } from './importAnalysis'
|
|
8
|
-
import { cssPlugin, cssPostPlugin } from './css'
|
|
9
|
-
import { assetPlugin } from './asset'
|
|
10
|
-
import { clientInjectionsPlugin } from './clientInjections'
|
|
11
|
-
import { htmlInlineScriptProxyPlugin } from './html'
|
|
12
|
-
import { wasmPlugin } from './wasm'
|
|
13
|
-
import { modulePreloadPolyfillPlugin } from './modulePreloadPolyfill'
|
|
14
|
-
import { webWorkerPlugin } from './worker'
|
|
15
|
-
import { preAliasPlugin } from './preAlias'
|
|
16
|
-
import { definePlugin } from './define'
|
|
17
|
-
|
|
18
|
-
export async function resolvePlugins(
|
|
19
|
-
config: ResolvedConfig,
|
|
20
|
-
prePlugins: Plugin[],
|
|
21
|
-
normalPlugins: Plugin[],
|
|
22
|
-
postPlugins: Plugin[]
|
|
23
|
-
): Promise<Plugin[]> {
|
|
24
|
-
const isBuild = config.command === 'build'
|
|
25
|
-
|
|
26
|
-
const buildPlugins = isBuild
|
|
27
|
-
? (await import('../build')).resolveBuildPlugins(config)
|
|
28
|
-
: { pre: [], post: [] }
|
|
29
|
-
|
|
30
|
-
return [
|
|
31
|
-
isBuild ? null : preAliasPlugin(),
|
|
32
|
-
aliasPlugin({ entries: config.resolve.alias }),
|
|
33
|
-
...prePlugins,
|
|
34
|
-
config.build.polyfillModulePreload
|
|
35
|
-
? modulePreloadPolyfillPlugin(config)
|
|
36
|
-
: null,
|
|
37
|
-
resolvePlugin({
|
|
38
|
-
...config.resolve,
|
|
39
|
-
root: config.root,
|
|
40
|
-
isProduction: config.isProduction,
|
|
41
|
-
isBuild,
|
|
42
|
-
ssrConfig: config.ssr,
|
|
43
|
-
asSrc: true
|
|
44
|
-
}),
|
|
45
|
-
htmlInlineScriptProxyPlugin(),
|
|
46
|
-
cssPlugin(config),
|
|
47
|
-
config.esbuild !== false ? esbuildPlugin(config.esbuild) : null,
|
|
48
|
-
jsonPlugin(
|
|
49
|
-
{
|
|
50
|
-
namedExports: true,
|
|
51
|
-
...config.json
|
|
52
|
-
},
|
|
53
|
-
isBuild
|
|
54
|
-
),
|
|
55
|
-
wasmPlugin(config),
|
|
56
|
-
webWorkerPlugin(config),
|
|
57
|
-
assetPlugin(config),
|
|
58
|
-
...normalPlugins,
|
|
59
|
-
definePlugin(config),
|
|
60
|
-
cssPostPlugin(config),
|
|
61
|
-
...buildPlugins.pre,
|
|
62
|
-
...postPlugins,
|
|
63
|
-
...buildPlugins.post,
|
|
64
|
-
// internal server-only plugins are always applied after everything else
|
|
65
|
-
...(isBuild
|
|
66
|
-
? []
|
|
67
|
-
: [clientInjectionsPlugin(config), importAnalysisPlugin(config)])
|
|
68
|
-
].filter(Boolean) as Plugin[]
|
|
69
|
-
}
|
package/src/node/plugins/json.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://github.com/rollup/plugins/blob/master/packages/json/src/index.js
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file at
|
|
6
|
-
* https://github.com/rollup/plugins/blob/master/LICENSE
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { dataToEsm } from '@rollup/pluginutils'
|
|
10
|
-
import { Plugin } from 'rollup'
|
|
11
|
-
import { SPECIAL_QUERY_RE } from '../constants'
|
|
12
|
-
|
|
13
|
-
export interface JsonOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Generate a named export for every property of the JSON object
|
|
16
|
-
* @default true
|
|
17
|
-
*/
|
|
18
|
-
namedExports?: boolean
|
|
19
|
-
/**
|
|
20
|
-
* Generate performant output as JSON.parse("stringified").
|
|
21
|
-
* Enabling this will disable namedExports.
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
stringify?: boolean
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Custom json filter for vite
|
|
28
|
-
const jsonExtRE = /\.json($|\?)(?!commonjs-proxy)/
|
|
29
|
-
|
|
30
|
-
export function jsonPlugin(
|
|
31
|
-
options: JsonOptions = {},
|
|
32
|
-
isBuild: boolean
|
|
33
|
-
): Plugin {
|
|
34
|
-
return {
|
|
35
|
-
name: 'vite:json',
|
|
36
|
-
|
|
37
|
-
transform(json, id) {
|
|
38
|
-
if (!jsonExtRE.test(id)) return null
|
|
39
|
-
if (SPECIAL_QUERY_RE.test(id)) return null
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
if (options.stringify) {
|
|
43
|
-
if (isBuild) {
|
|
44
|
-
return {
|
|
45
|
-
// during build, parse then double-stringify to remove all
|
|
46
|
-
// unnecessary whitespaces to reduce bundle size.
|
|
47
|
-
code: `export default JSON.parse(${JSON.stringify(
|
|
48
|
-
JSON.stringify(JSON.parse(json))
|
|
49
|
-
)})`,
|
|
50
|
-
map: { mappings: '' }
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
return `export default JSON.parse(${JSON.stringify(json)})`
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const parsed = JSON.parse(json)
|
|
58
|
-
return {
|
|
59
|
-
code: dataToEsm(parsed, {
|
|
60
|
-
preferConst: true,
|
|
61
|
-
namedExports: options.namedExports
|
|
62
|
-
}),
|
|
63
|
-
map: { mappings: '' }
|
|
64
|
-
}
|
|
65
|
-
} catch (e) {
|
|
66
|
-
const errorMessageList = /[\d]+/.exec(e.message)
|
|
67
|
-
const position = errorMessageList && parseInt(errorMessageList[0], 10)
|
|
68
|
-
const msg = position
|
|
69
|
-
? `, invalid JSON syntax found at line ${position}`
|
|
70
|
-
: `.`
|
|
71
|
-
this.error(`Failed to parse JSON file` + msg, e.idx)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs'
|
|
2
|
-
import { Plugin } from '..'
|
|
3
|
-
import { cleanUrl } from '../utils'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A plugin to provide build load fallback for arbitrary request with queries.
|
|
7
|
-
*/
|
|
8
|
-
export function loadFallbackPlugin(): Plugin {
|
|
9
|
-
return {
|
|
10
|
-
name: 'vite:load-fallback',
|
|
11
|
-
async load(id) {
|
|
12
|
-
try {
|
|
13
|
-
return fs.readFile(cleanUrl(id), 'utf-8')
|
|
14
|
-
} catch (e) {
|
|
15
|
-
return fs.readFile(id, 'utf-8')
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { OutputChunk } from 'rollup'
|
|
3
|
-
import { ResolvedConfig } from '..'
|
|
4
|
-
import { Plugin } from '../plugin'
|
|
5
|
-
import { chunkToEmittedCssFileMap } from './css'
|
|
6
|
-
import { chunkToEmittedAssetsMap } from './asset'
|
|
7
|
-
import { normalizePath } from '../utils'
|
|
8
|
-
|
|
9
|
-
export type Manifest = Record<string, ManifestChunk>
|
|
10
|
-
|
|
11
|
-
export interface ManifestChunk {
|
|
12
|
-
src?: string
|
|
13
|
-
file: string
|
|
14
|
-
css?: string[]
|
|
15
|
-
assets?: string[]
|
|
16
|
-
isEntry?: boolean
|
|
17
|
-
isDynamicEntry?: boolean
|
|
18
|
-
imports?: string[]
|
|
19
|
-
dynamicImports?: string[]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function manifestPlugin(config: ResolvedConfig): Plugin {
|
|
23
|
-
const manifest: Manifest = {}
|
|
24
|
-
|
|
25
|
-
let outputCount: number
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
name: 'vite:manifest',
|
|
29
|
-
|
|
30
|
-
buildStart() {
|
|
31
|
-
outputCount = 0
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
generateBundle({ format }, bundle) {
|
|
35
|
-
function getChunkName(chunk: OutputChunk) {
|
|
36
|
-
if (chunk.facadeModuleId) {
|
|
37
|
-
let name = normalizePath(
|
|
38
|
-
path.relative(config.root, chunk.facadeModuleId)
|
|
39
|
-
)
|
|
40
|
-
if (format === 'system' && !chunk.name.includes('-legacy')) {
|
|
41
|
-
const ext = path.extname(name)
|
|
42
|
-
name = name.slice(0, -ext.length) + `-legacy` + ext
|
|
43
|
-
}
|
|
44
|
-
return name
|
|
45
|
-
} else {
|
|
46
|
-
return `_` + path.basename(chunk.fileName)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getInternalImports(imports: string[]): string[] {
|
|
51
|
-
const filteredImports: string[] = []
|
|
52
|
-
|
|
53
|
-
for (const file of imports) {
|
|
54
|
-
if (bundle[file] === undefined) {
|
|
55
|
-
continue
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
filteredImports.push(getChunkName(bundle[file] as OutputChunk))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return filteredImports
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function createChunk(chunk: OutputChunk): ManifestChunk {
|
|
65
|
-
const manifestChunk: ManifestChunk = {
|
|
66
|
-
file: chunk.fileName
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (chunk.facadeModuleId) {
|
|
70
|
-
manifestChunk.src = getChunkName(chunk)
|
|
71
|
-
}
|
|
72
|
-
if (chunk.isEntry) {
|
|
73
|
-
manifestChunk.isEntry = true
|
|
74
|
-
}
|
|
75
|
-
if (chunk.isDynamicEntry) {
|
|
76
|
-
manifestChunk.isDynamicEntry = true
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (chunk.imports.length) {
|
|
80
|
-
const internalImports = getInternalImports(chunk.imports)
|
|
81
|
-
if (internalImports.length > 0) {
|
|
82
|
-
manifestChunk.imports = internalImports
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (chunk.dynamicImports.length) {
|
|
87
|
-
const internalImports = getInternalImports(chunk.dynamicImports)
|
|
88
|
-
if (internalImports.length > 0) {
|
|
89
|
-
manifestChunk.dynamicImports = internalImports
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const cssFiles = chunkToEmittedCssFileMap.get(chunk)
|
|
94
|
-
if (cssFiles) {
|
|
95
|
-
manifestChunk.css = [...cssFiles]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const assets = chunkToEmittedAssetsMap.get(chunk)
|
|
99
|
-
if (assets) [(manifestChunk.assets = [...assets])]
|
|
100
|
-
|
|
101
|
-
return manifestChunk
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
for (const file in bundle) {
|
|
105
|
-
const chunk = bundle[file]
|
|
106
|
-
if (chunk.type === 'chunk') {
|
|
107
|
-
manifest[getChunkName(chunk)] = createChunk(chunk)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
outputCount++
|
|
112
|
-
const output = config.build.rollupOptions?.output
|
|
113
|
-
const outputLength = Array.isArray(output) ? output.length : 1
|
|
114
|
-
if (outputCount >= outputLength) {
|
|
115
|
-
this.emitFile({
|
|
116
|
-
fileName: `manifest.json`,
|
|
117
|
-
type: 'asset',
|
|
118
|
-
source: JSON.stringify(manifest, null, 2)
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|