networkteam / neos-vite
此包最新版本(0.3.1)没有可用的许可信息。
将 Vite 集成到 Neos CMS 中进行资源打包
This package is auto-updated.
Last update: 2024-09-18 15:15:23 UTC
README
安装
转到您的站点包
cd DistributionPackages/Your.Site
1. 通过 composer 安装包
composer require networkteam/neos-vite
2. 通过 NPM(或 Yarn、pnpm)安装 Vite
npm install --save-dev vite
3. 在您的站点包中创建一个 vite.config.mjs
文件
import { defineConfig } from "vite"; export default defineConfig((configEnv) => ({ base: "./", build: { // generate .vite/manifest.json in outDir manifest: true, rollupOptions: { // overwrite default .html entry input: { footer: "Resources/Private/Javascript/footer.js", header: "Resources/Private/Javascript/header.js", }, output: { // The Flowpack.CacheBuster package adds a `?bust` get parameter with a hash based on the file content. // This leads to issues with files imported from the manifest, as they may be loaded twice. // (Once with the bust parameter and once without, as they are technically two different URLs.) // To work around this we add a "bust" infix so CacheBuster skips adding the bust parameter. entryFileNames: "assets/[name]-bust-[hash].js", // If you use this output option the Fusion object will just work™️ dir: "Resources/Public/Dist", }, }, }, }));
4. 现在您可以在 Fusion 文件中包含用于开发/生产的 Vite 资产
header = Networkteam.Neos.Vite:Asset {
entry = 'Resources/Private/Javascript/header.js'
}
此 Fusion 对象将根据 FLOW_CONTEXT 使用不同的包含
- 开发:加载为站点配置的开发服务器中的入口(默认为 http://localhost:5173/)
- 生产:根据生成的清单文件,它将包含带有 CSS 和递归导入的哈希资源
默认情况下,清单预期在 Resources/Public/Dist
中,但可以通过覆盖 Fusion 属性进行更改
prototype(Networkteam.Neos.Vite:Asset) {
// ...
outputPathPattern = 'resource://{sitePackageKey}/Public/Dist'
manifest = '.vite/manifest.json'
}
附加功能:您可以生成清单中条目的 URL
这将仅返回没有考虑导入的条目文件的 URL。
示例:SVG spritemap(使用 vite-plugin-svg-spritemap)
src = Networkteam.Neos.Vite:AssetUrl {
entry = 'spritemap.svg'
}
多站点
为每个站点配置单独的 Vite 配置,通过在每个站点包中添加一个带有相应 vite.config.mjs
文件的 Vite 设置。确保通过配置 Vite 配置中的 server.port
选项在每个站点上运行不同的端口。
在您的 Settings.yaml
中为每个站点添加设置
Networkteam: Neos: Vite: server: # This is the default setting if no configuration part is found for the site package key _default: url: http://localhost:5173/ # Specify server configuration for a specific site package key MyExample.Site: url: http://localhost:5174/
确保为每个站点包运行多个 Vite 服务器。