vite-plugin-symfony
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -9,5 +9,5 @@ "use strict"; | ||
const { origin } = config.server; | ||
for (const [entryName, entryPath] of Object.entries(parseInput(config))) { | ||
for (const [entryName, { entryPath, entryType }] of Object.entries(parseInput(config))) { | ||
entryPoints[entryName] = { | ||
js: [`${origin}${config.base}${entryPath}`], | ||
[entryType]: [`${origin}${config.base}${entryPath}`], | ||
}; | ||
@@ -20,4 +20,4 @@ } | ||
const entryPoints = {}; | ||
for (const [entryName, entryPath] of Object.entries(parseInput(config))) { | ||
entryPoints[entryName] = parseManifestEntry(entryPath, manifest, config); | ||
for (const [entryName, entry] of Object.entries(parseInput(config))) { | ||
entryPoints[entryName] = parseManifestEntry(entry, manifest, config); | ||
} | ||
@@ -27,3 +27,3 @@ return entryPoints; | ||
exports.getBuildEntryPoints = getBuildEntryPoints; | ||
const parseManifestEntry = (entryPath, manifest, config) => { | ||
const parseManifestEntry = ({ entryPath, entryType }, manifest, config) => { | ||
if (!manifest[entryPath]) { | ||
@@ -38,3 +38,6 @@ throw new Error(`Entrypoint ${entryPath} not defined in the manifest`); | ||
for (const importEntryName of manifestEntry.imports) { | ||
const { css: importCss, preload: importPreload } = parseManifestEntry(importEntryName, manifest, config); | ||
const { css: importCss, preload: importPreload } = parseManifestEntry({ | ||
entryPath: importEntryName, | ||
entryType: "js", | ||
}, manifest, config); | ||
for (const dependency of importCss) { | ||
@@ -53,3 +56,8 @@ if (css.indexOf(dependency) === -1) { | ||
if (manifestEntry.isEntry) { | ||
js.push(`${config.base}${manifestEntry.file}`); | ||
if (entryType === "js") { | ||
js.push(`${config.base}${manifestEntry.file}`); | ||
} | ||
else if (entryType === "css") { | ||
css.push(`${config.base}${manifestEntry.file}`); | ||
} | ||
} | ||
@@ -76,6 +84,11 @@ else if (preload.indexOf(`${config.base}${manifestEntry.file}`) === -1) { | ||
} | ||
const entryRelativePath = entryAbsolutePath.substr(config.root.length + 1); | ||
inputParsed[entryName] = entryRelativePath; | ||
const extension = (0, path_1.extname)(entryPath); | ||
const entryType = [".css", ".scss", ".sass", ".less", ".styl", ".stylus", ".postcss"].indexOf(extension) !== -1 ? "css" : "js"; | ||
const entryRelativePath = entryAbsolutePath.substring(config.root.length + 1); | ||
inputParsed[entryName] = { | ||
entryType, | ||
entryPath: entryRelativePath, | ||
}; | ||
} | ||
return inputParsed; | ||
}; |
@@ -40,3 +40,2 @@ "use strict"; | ||
entryPointsPath = (0, path_1.resolve)(config.root, config.build.outDir, "entrypoints.json"); | ||
assetsPath = (0, path_1.resolve)(config.root, config.build.outDir, "assets.json"); | ||
if (config.env.DEV) { | ||
@@ -43,0 +42,0 @@ const buildDir = (0, path_1.resolve)(config.root, config.build.outDir); |
{ | ||
"name": "vite-plugin-symfony", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { cwd } from "process"; | ||
import { resolve } from "path"; | ||
import { resolve, extname } from "path"; | ||
import type { ResolvedConfig } from "vite"; | ||
@@ -9,5 +9,5 @@ | ||
for (const [entryName, entryPath] of Object.entries(parseInput(config))) { | ||
for (const [entryName, { entryPath, entryType }] of Object.entries(parseInput(config))) { | ||
entryPoints[entryName] = { | ||
js: [`${origin}${config.base}${entryPath}`], | ||
[entryType]: [`${origin}${config.base}${entryPath}`], | ||
}; | ||
@@ -21,4 +21,4 @@ } | ||
for (const [entryName, entryPath] of Object.entries(parseInput(config))) { | ||
entryPoints[entryName] = parseManifestEntry(entryPath, manifest, config); | ||
for (const [entryName, entry] of Object.entries(parseInput(config))) { | ||
entryPoints[entryName] = parseManifestEntry(entry, manifest, config); | ||
} | ||
@@ -29,3 +29,3 @@ | ||
const parseManifestEntry = (entryPath: string, manifest: Manifest, config: ResolvedConfig) => { | ||
const parseManifestEntry = ({ entryPath, entryType }: ParsedEntry, manifest: Manifest, config: ResolvedConfig) => { | ||
if (!manifest[entryPath]) { | ||
@@ -42,3 +42,10 @@ throw new Error(`Entrypoint ${entryPath} not defined in the manifest`); | ||
for (const importEntryName of manifestEntry.imports) { | ||
const { css: importCss, preload: importPreload } = parseManifestEntry(importEntryName, manifest, config); | ||
const { css: importCss, preload: importPreload } = parseManifestEntry( | ||
{ | ||
entryPath: importEntryName, | ||
entryType: "js", | ||
}, | ||
manifest, | ||
config, | ||
); | ||
@@ -59,3 +66,7 @@ for (const dependency of importCss) { | ||
if (manifestEntry.isEntry) { | ||
js.push(`${config.base}${manifestEntry.file}`); | ||
if (entryType === "js") { | ||
js.push(`${config.base}${manifestEntry.file}`); | ||
} else if (entryType === "css") { | ||
css.push(`${config.base}${manifestEntry.file}`); | ||
} | ||
} else if (preload.indexOf(`${config.base}${manifestEntry.file}`) === -1) { | ||
@@ -87,5 +98,13 @@ preload.push(`${config.base}${manifestEntry.file}`); | ||
const entryRelativePath = entryAbsolutePath.substr(config.root.length + 1); | ||
const extension = extname(entryPath); | ||
inputParsed[entryName] = entryRelativePath; | ||
const entryType = | ||
[".css", ".scss", ".sass", ".less", ".styl", ".stylus", ".postcss"].indexOf(extension) !== -1 ? "css" : "js"; | ||
const entryRelativePath = entryAbsolutePath.substring(config.root.length + 1); | ||
inputParsed[entryName] = { | ||
entryType, | ||
entryPath: entryRelativePath, | ||
}; | ||
} | ||
@@ -92,0 +111,0 @@ |
@@ -47,3 +47,2 @@ import type { Plugin, UserConfig } from "vite"; | ||
entryPointsPath = resolve(config.root, config.build.outDir, "entrypoints.json"); | ||
assetsPath = resolve(config.root, config.build.outDir, "assets.json"); | ||
@@ -50,0 +49,0 @@ if (config.env.DEV) { |
@@ -11,3 +11,3 @@ type EntryPointsFile = { | ||
type EntryPoint = { | ||
js: string[]; | ||
js?: string[]; | ||
css?: string[]; | ||
@@ -21,5 +21,10 @@ preload?: string[]; | ||
type ParsedInput = { | ||
[k: string]: string; | ||
[k: string]: ParsedEntry; | ||
}; | ||
type ParsedEntry = { | ||
entryType: "js" | "css"; | ||
entryPath: string; | ||
}; | ||
type ManifestEntry = { | ||
@@ -26,0 +31,0 @@ file: string; |
29779
472