Skip to content

Commit 707d839

Browse files
committed
chore: disable dev plugin relate logic
1 parent a0d50f6 commit 707d839

File tree

7 files changed

+82
-79
lines changed

7 files changed

+82
-79
lines changed

packages/vite/src/node/plugins/asset.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
204204
// Force rollup to keep this module from being shared between other entry points if it's an entrypoint.
205205
// If the resulting chunk is empty, it will be removed in generateBundle.
206206
moduleSideEffects:
207-
config.command === 'build' && this.getModuleInfo(id)?.isEntry
207+
// config.command === 'build' &&
208+
this.getModuleInfo(id)?.isEntry
208209
? 'no-treeshake'
209210
: false,
210-
meta: config.command === 'build' ? { 'vite:asset': true } : undefined,
211+
meta: /* config.command === 'build' ? */ { 'vite:asset': true } /* : undefined */,
211212
moduleType: 'js', // NOTE: needs to be set to avoid double `export default` in `.txt`s
212213
}
213214
},
@@ -262,7 +263,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
262263

263264
// do not emit assets for SSR build
264265
if (
265-
config.command === 'build' &&
266+
// config.command === 'build' &&
266267
!this.environment.config.build.emitAssets
267268
) {
268269
for (const file in bundle) {
@@ -283,12 +284,12 @@ export async function fileToUrl(
283284
pluginContext: PluginContext,
284285
id: string,
285286
): Promise<string> {
286-
const { environment } = pluginContext
287-
if (environment.config.command === 'serve') {
288-
return fileToDevUrl(environment, id)
289-
} else {
287+
// const { environment } = pluginContext
288+
// if (environment.config.command === 'serve') {
289+
// return fileToDevUrl(environment, id)
290+
// } else {
290291
return fileToBuiltUrl(pluginContext, id)
291-
}
292+
// }
292293
}
293294

294295
export async function fileToDevUrl(
@@ -355,10 +356,10 @@ export function publicFileToBuiltUrl(
355356
url: string,
356357
config: ResolvedConfig,
357358
): string {
358-
if (config.command !== 'build') {
359-
// We don't need relative base or renderBuiltUrl support during dev
360-
return joinUrlSegments(config.decodedBase, url)
361-
}
359+
// if (config.command !== 'build') {
360+
// // We don't need relative base or renderBuiltUrl support during dev
361+
// return joinUrlSegments(config.decodedBase, url)
362+
// }
362363
const hash = getHash(url)
363364
let cache = publicAssetUrlCache.get(config)
364365
if (!cache) {

packages/vite/src/node/plugins/assetImportMetaUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
3737
...config.resolve,
3838
root: config.root,
3939
isProduction: config.isProduction,
40-
isBuild: config.command === 'build',
40+
isBuild: true , // config.command === 'build'
4141
packageCache: config.packageCache,
4242
asSrc: true,
4343
}

packages/vite/src/node/plugins/css.ts

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import type {
3838
} from 'lightningcss'
3939
import type { CustomPluginOptionsVite } from 'types/metadata'
4040
import type { EsbuildTransformOptions } from 'types/internal/esbuildOptions'
41-
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
41+
// import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
4242
import type { EnvironmentModuleNode } from '../server/moduleGraph'
4343
import {
4444
createToImportMetaURLBasedRelativeRuntime,
@@ -48,7 +48,7 @@ import {
4848
} from '../build'
4949
import type { LibraryOptions } from '../build'
5050
import {
51-
CLIENT_PUBLIC_PATH,
51+
// CLIENT_PUBLIC_PATH,
5252
CSS_LANGS_RE,
5353
DEV_PROD_CONDITION,
5454
ESBUILD_MODULES_TARGET,
@@ -72,7 +72,7 @@ import {
7272
isDataUrl,
7373
isExternalUrl,
7474
isObject,
75-
joinUrlSegments,
75+
// joinUrlSegments,
7676
mergeWithDefaults,
7777
normalizePath,
7878
processSrcSet,
@@ -286,17 +286,17 @@ const postcssConfigCache = new WeakMap<
286286
PostCSSConfigResult | null | Promise<PostCSSConfigResult | null>
287287
>()
288288

289-
function encodePublicUrlsInCSS(config: ResolvedConfig) {
290-
return config.command === 'build'
291-
}
289+
// function encodePublicUrlsInCSS(config: ResolvedConfig) {
290+
// return config.command === 'build'
291+
// }
292292

293293
const cssUrlAssetRE = /__VITE_CSS_URL__([\da-f]+)__/g
294294

295295
/**
296296
* Plugin applied before user plugins
297297
*/
298298
export function cssPlugin(config: ResolvedConfig): Plugin {
299-
const isBuild = config.command === 'build'
299+
// const isBuild = config.command === 'build'
300300
let moduleCache: Map<string, Record<string, string>>
301301

302302
const idResolver = createBackCompatIdResolver(config, {
@@ -353,15 +353,15 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
353353

354354
// *.css?url
355355
// in dev, it's handled by assets plugin.
356-
if (isBuild) {
356+
// if (isBuild) {
357357
id = injectQuery(removeUrlQuery(id), 'transform-only')
358358
return (
359359
`import ${JSON.stringify(id)};` +
360360
`export default "__VITE_CSS_URL__${Buffer.from(id).toString(
361361
'hex',
362362
)}__"`
363363
)
364-
}
364+
// }
365365
}
366366
},
367367
},
@@ -391,19 +391,19 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
391391
const urlResolver: CssUrlResolver = async (url, importer) => {
392392
const decodedUrl = decodeURI(url)
393393
if (checkPublicFile(decodedUrl, config)) {
394-
if (encodePublicUrlsInCSS(config)) {
394+
// if (encodePublicUrlsInCSS(config)) {
395395
return [publicFileToBuiltUrl(decodedUrl, config), undefined]
396-
} else {
397-
return [joinUrlSegments(config.base, decodedUrl), undefined]
398-
}
396+
// } else {
397+
// return [joinUrlSegments(config.base, decodedUrl), undefined]
398+
// }
399399
}
400400
const [id, fragment] = decodedUrl.split('#')
401401
let resolved = await resolveUrl(id, importer)
402402
if (resolved) {
403403
if (fragment) resolved += '#' + fragment
404404
return [await fileToUrl(this, resolved), resolved]
405405
}
406-
if (config.command === 'build') {
406+
// if (config.command === 'build') {
407407
const isExternal = config.build.rollupOptions.external
408408
? resolveUserExternal(
409409
config.build.rollupOptions.external,
@@ -419,7 +419,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
419419
`\n${decodedUrl} referenced in ${id} didn't resolve at build time, it will remain unchanged to be resolved at runtime`,
420420
)
421421
}
422-
}
422+
// }
423423
return [url, undefined]
424424
}
425425

@@ -578,46 +578,47 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
578578
!inlined &&
579579
dataToEsm(modules, { namedExports: true, preferConst: true })
580580

581-
if (config.command === 'serve') {
582-
const getContentWithSourcemap = async (content: string) => {
583-
if (config.css.devSourcemap) {
584-
const sourcemap = this.getCombinedSourcemap()
585-
if (sourcemap.mappings) {
586-
await injectSourcesContent(
587-
sourcemap,
588-
cleanUrl(id),
589-
config.logger,
590-
)
591-
}
592-
return getCodeWithSourcemap('css', content, sourcemap)
593-
}
594-
return content
595-
}
596-
597-
if (isDirectCSSRequest(id)) {
598-
return null
599-
}
600-
if (inlined) {
601-
return `export default ${JSON.stringify(css)}`
602-
}
603-
if (this.environment.config.consumer === 'server') {
604-
return modulesCode || 'export {}'
605-
}
606-
607-
const cssContent = await getContentWithSourcemap(css)
608-
const code = [
609-
`import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify(
610-
path.posix.join(config.base, CLIENT_PUBLIC_PATH),
611-
)}`,
612-
`const __vite__id = ${JSON.stringify(id)}`,
613-
`const __vite__css = ${JSON.stringify(cssContent)}`,
614-
`__vite__updateStyle(__vite__id, __vite__css)`,
615-
// css modules exports change on edit so it can't self accept
616-
`${modulesCode || 'import.meta.hot.accept()'}`,
617-
`import.meta.hot.prune(() => __vite__removeStyle(__vite__id))`,
618-
].join('\n')
619-
return { code, map: { mappings: '' } }
620-
}
581+
// TODO(underfin): css hmr
582+
// if (config.command === 'serve') {
583+
// const getContentWithSourcemap = async (content: string) => {
584+
// if (config.css.devSourcemap) {
585+
// const sourcemap = this.getCombinedSourcemap()
586+
// if (sourcemap.mappings) {
587+
// await injectSourcesContent(
588+
// sourcemap,
589+
// cleanUrl(id),
590+
// config.logger,
591+
// )
592+
// }
593+
// return getCodeWithSourcemap('css', content, sourcemap)
594+
// }
595+
// return content
596+
// }
597+
598+
// if (isDirectCSSRequest(id)) {
599+
// return null
600+
// }
601+
// if (inlined) {
602+
// return `export default ${JSON.stringify(css)}`
603+
// }
604+
// if (this.environment.config.consumer === 'server') {
605+
// return modulesCode || 'export {}'
606+
// }
607+
608+
// const cssContent = await getContentWithSourcemap(css)
609+
// const code = [
610+
// `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify(
611+
// path.posix.join(config.base, CLIENT_PUBLIC_PATH),
612+
// )}`,
613+
// `const __vite__id = ${JSON.stringify(id)}`,
614+
// `const __vite__css = ${JSON.stringify(cssContent)}`,
615+
// `__vite__updateStyle(__vite__id, __vite__css)`,
616+
// // css modules exports change on edit so it can't self accept
617+
// `${modulesCode || 'import.meta.hot.accept()'}`,
618+
// `import.meta.hot.prune(() => __vite__removeStyle(__vite__id))`,
619+
// ].join('\n')
620+
// return { code, map: { mappings: '' } }
621+
// }
621622

622623
// build CSS handling ----------------------------------------------------
623624

@@ -699,7 +700,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
699700
chunkCSS: string,
700701
cssAssetName: string,
701702
) => {
702-
const encodedPublicUrls = encodePublicUrlsInCSS(config)
703+
const encodedPublicUrls = true
703704

704705
const relative = config.base === './' || config.base === ''
705706
const cssAssetDirname =
@@ -3493,9 +3494,10 @@ async function compileLightningCSS(
34933494
},
34943495
minify: config.isProduction && !!config.build.cssMinify,
34953496
sourceMap:
3496-
config.command === 'build'
3497-
? !!config.build.sourcemap
3498-
: config.css.devSourcemap,
3497+
// config.command === 'build' ?
3498+
!!config.build.sourcemap,
3499+
// TODO(underfin): deprecate css.devSourcemap
3500+
// : config.css.devSourcemap,
34993501
analyzeDependencies: true,
35003502
cssModules: cssModuleRE.test(id)
35013503
? (config.css.lightningcss?.cssModules ?? true)

packages/vite/src/node/plugins/define.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ export async function replaceDefine(
205205
sourceType: 'module',
206206
define,
207207
sourcemap:
208-
environment.config.command === 'build'
209-
? !!environment.config.build.sourcemap
210-
: true,
208+
// environment.config.command === 'build' ?
209+
!!environment.config.build.sourcemap
210+
// : true,
211211
})
212212

213213
if (result.errors.length > 0) {

packages/vite/src/node/plugins/modulePreloadPolyfill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function modulePreloadPolyfillPlugin(config: ResolvedConfig): Plugin {
2222
handler(_id) {
2323
// `isModernFlag` is only available during build since it is resolved by `vite:build-import-analysis`
2424
if (
25-
config.command !== 'build' ||
25+
// config.command !== 'build' ||
2626
this.environment.config.consumer !== 'client'
2727
) {
2828
return ''

packages/vite/src/node/plugins/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export function webWorkerPostPlugin(): Plugin {
285285
}
286286

287287
export function webWorkerPlugin(config: ResolvedConfig): Plugin {
288-
const isBuild = config.command === 'build'
288+
const isBuild = true
289289
const isWorker = config.isWorker
290290

291291
return {

packages/vite/src/node/plugins/workerImportMetaUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ async function getWorkerType(
181181
}
182182

183183
export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
184-
const isBuild = config.command === 'build'
184+
const isBuild = true
185185
let workerResolver: ResolveIdFn
186186

187187
const fsResolveOptions: InternalResolveOptions = {
188188
...config.resolve,
189189
root: config.root,
190190
isProduction: config.isProduction,
191-
isBuild: config.command === 'build',
191+
isBuild,
192192
packageCache: config.packageCache,
193193
asSrc: true,
194194
}

0 commit comments

Comments
 (0)