Skip to content

Commit f6b04d7

Browse files
committed
remove workaround adding CSS to manifest
1 parent 9379a04 commit f6b04d7

File tree

1 file changed

+1
-66
lines changed

1 file changed

+1
-66
lines changed

src/index.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs'
22
import { AddressInfo } from 'net'
33
import path from 'path'
44
import colors from 'picocolors'
5-
import { Plugin, loadEnv, UserConfig, ConfigEnv, Manifest, ResolvedConfig, SSROptions, normalizePath, PluginOption } from 'vite'
5+
import { Plugin, loadEnv, UserConfig, ConfigEnv, ResolvedConfig, SSROptions, PluginOption } from 'vite'
66
import fullReload, { Config as FullReloadConfig } from 'vite-plugin-full-reload'
77

88
interface PluginConfig {
@@ -85,7 +85,6 @@ export default function laravel(config: string|string[]|PluginConfig): [LaravelP
8585
function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlugin {
8686
let viteDevServerUrl: DevServerUrl
8787
let resolvedConfig: ResolvedConfig
88-
const cssManifest: Manifest = {}
8988

9089
const defaultAliases: Record<string, string> = {
9190
'@': '/resources/js',
@@ -199,50 +198,6 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
199198

200199
next()
201200
})
202-
},
203-
204-
// The following two hooks are a workaround to help solve a "flash of unstyled content" with Blade.
205-
// They add any CSS entry points into the manifest because Vite does not currently do this.
206-
renderChunk(_, chunk) {
207-
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`
208-
const cssLangRE = new RegExp(cssLangs)
209-
210-
if (! chunk.isEntry || chunk.facadeModuleId === null || ! cssLangRE.test(chunk.facadeModuleId)) {
211-
return null
212-
}
213-
214-
const relativeChunkPath = normalizePath(path.relative(resolvedConfig.root, chunk.facadeModuleId))
215-
216-
cssManifest[relativeChunkPath] = {
217-
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
218-
/* @ts-ignore */
219-
file: Array.from(chunk.viteMetadata.importedCss)[0] ?? chunk.fileName,
220-
src: relativeChunkPath,
221-
isEntry: true,
222-
}
223-
224-
return null
225-
},
226-
writeBundle() {
227-
const manifestConfig = resolveManifestConfig(resolvedConfig)
228-
229-
if (manifestConfig === false) {
230-
return;
231-
}
232-
233-
const manifestPath = path.resolve(resolvedConfig.root, resolvedConfig.build.outDir, manifestConfig)
234-
235-
if (! fs.existsSync(manifestPath)) {
236-
// The manifest does not exist yet when first writing the legacy asset bundle.
237-
return;
238-
}
239-
240-
const manifest = JSON.parse(fs.readFileSync(manifestPath).toString())
241-
const newManifest = {
242-
...manifest,
243-
...cssManifest,
244-
}
245-
fs.writeFileSync(manifestPath, JSON.stringify(newManifest, null, 2))
246201
}
247202
}
248203
}
@@ -339,26 +294,6 @@ function resolveOutDir(config: Required<PluginConfig>, ssr: boolean): string|und
339294
return path.join(config.publicDirectory, config.buildDirectory)
340295
}
341296

342-
/**
343-
* Resolve the Vite manifest config from the configuration.
344-
*/
345-
function resolveManifestConfig(config: ResolvedConfig): string|false
346-
{
347-
const manifestConfig = config.build.ssr
348-
? config.build.ssrManifest
349-
: config.build.manifest;
350-
351-
if (manifestConfig === false) {
352-
return false
353-
}
354-
355-
if (manifestConfig === true) {
356-
return config.build.ssr ? 'ssr-manifest.json' : 'manifest.json'
357-
}
358-
359-
return manifestConfig
360-
}
361-
362297
function resolveFullReloadConfig({ refresh: config }: Required<PluginConfig>): PluginOption[]{
363298
if (typeof config === 'boolean') {
364299
return [];

0 commit comments

Comments
 (0)