Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,64 @@ export default defineConfig((configEnv) => ({

### 4. You can now include Vite assets for development / production in your Fusion files:

Let the package include everything for you, including [vite development scripts](https://vitejs.dev/guide/backend-integration):

```fusion
prototype(Customer.Base:Document.DefaultPage) < prototype(Neos.Neos:Page) {
head {
javascript.base = Networkteam.Neos.Vite:Head.Assets {
header = Networkteam.Neos.Vite:Asset {
entry = 'Resources/Private/Javascript/header.js'
}
}
}

bodyAssets = Networkteam.Neos.Vite:Body.Assets {
footer = Networkteam.Neos.Vite:Asset {
entry = 'Resources/Private/Javascript/footer.js'
}

// Include development scripts needed by Vite, for example:
developmentOnlyScripts {
// here you have access to the Vite server URL via context variable `viteUrl`
pluginName = ${'<script type="module" src="' + viteUrl + '@vite-plugin/client"></script>'}
}
@position = 'before closingBodyTag'
}
}
```

Or, include everything manually using:

```fusion
header = Networkteam.Neos.Vite:Asset {
entry = 'Resources/Private/Javascript/header.js'
}

developmentOnlyScripts = Networkteam.Neos.Vite:Helper.DevelopmentOnlyScripts {
@context.viteUrl = ${Configuration.setting('Networkteam.Neos.Vite.server._default.url')}
pluginName = '<script type="module" src="' + viteUrl + '@vite-plugin/client"></script>'
}
```

You can also use development-only scripts as Condition with Prototype `Networkteam.Neos.Vite:Helper.IsDevelopmentOnly`:

```fusion
prototype(Customer.Base:Helper.SpritemapBaseUrl) < prototype(Neos.Fusion:Case) {
inDevelopmentMode {
condition = Networkteam.Neos.Vite:Helper.IsDevelopmentOnly
renderer = '#icon-'
}
default {
condition = ${false}
renderer = Neos.Fusion:Value {
@context.spritemap = Networkteam.Neos.Vite:AssetUrl {
entry = 'spritemap.svg'
}
value = ${spritemap + '#icon-'}
}
}
}
```

This Fusion object will use a different include based on the FLOW_CONTEXT:
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Fusion/Body/Assets.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
prototype(Networkteam.Neos.Vite:Body.Assets) < prototype(Neos.Fusion:Join) {
developmentOnlyScripts = Networkteam.Neos.Vite:Helper.DevelopmentOnlyScripts {
@context.viteUrl = ${Configuration.setting('Networkteam.Neos.Vite.server._default.url')}
// insert the vite client scripts
}
}
7 changes: 7 additions & 0 deletions Resources/Private/Fusion/Head/Assets.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prototype(Networkteam.Neos.Vite:Head.Assets) < prototype(Neos.Fusion:Join) {
developmentOnlyScripts = Networkteam.Neos.Vite:Helper.DevelopmentOnlyScripts {
@context.viteUrl = ${Configuration.setting('Networkteam.Neos.Vite.server._default.url')}
// Inject the react-refresh runtime into the page see: https://vitejs.dev/guide/backend-integration
reactRefresh = ${"<script type='module'>import RefreshRuntime from '" + viteUrl + "@react-refresh';RefreshRuntime.injectIntoGlobalHook(window);window.$RefreshReg$ = () => {};window.$RefreshSig$ = () => (type) => type;window.__vite_plugin_react_preamble_installed__ = true</script>"}
}
}
31 changes: 31 additions & 0 deletions Resources/Private/Fusion/Helper/DevelopmentOnly.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Usage:
* developmentOnlyScripts = Viebrockhaus.Base:Helper.DevelopmentOnlyScripts {
* @context.viteUrl = ${Configuration.setting('Networkteam.Neos.Vite.server._default.url')}
* 0 = ${'<script type="module" src="' + viteUrl + '@vite-plugin-svg-spritemap/client"></script>'}
* }
*
*/

prototype(Networkteam.Neos.Vite:Helper.DevelopmentOnlyScripts) < prototype(Neos.Fusion:Join) {
@context {
flowContext = ${Configuration.setting('Neos.Flow.core.context')}
}
@if.isDevelopmentContext = ${String.indexOf(flowContext, 'Development') >= 0}
}

prototype(Networkteam.Neos.Vite:Helper.IsDevelopmentOnly) < prototype(Neos.Fusion:Case) {
@context {
flowContext = ${Configuration.setting('Neos.Flow.core.context')}
}

inDevelopment {
condition = ${String.indexOf(flowContext, 'Development') >= 0}
renderer = ${true}
}

default {
condition = ${true}
renderer = ${false}
}
}