--- url: /guide/features.md --- # About Vituum and its features The main goal of Vituum is to add some additional features on top of Vite via plugins. It's also a bridge for developers who still depend on template engines or older front-end tools like **gulp** or **grunt** and want to migrate to **Vite**. Vituum can also be used as a small static site generator, but we recommend using [Astro](https://astro.build/) or [Eleventy](https://www.11ty.dev/) for a full SSG experience. Most of the features are optional and can be added via dedicated [Vite Plugins](/plugins/). ## Multi-page support Vituum makes it easy to use multiple `.html` files in Vite out of the box. So you can add glob patterns to [rollupOptions.input](https://vitejs.dev/guide/build.html#multi-page-app) and use multi-page routing in pages directory. ```javascript export default { build: { rollupOptions: { input: ['./src/pages/**/*.html'] } } } ``` You can use this to prototype fast without the need to change much in the config.By default, Vituum routes from `src/pages` directory. You can even enhance this with [PostHTML](/plugins/posthtml) syntax like `` to include small `html` components or use [Template Engines](/guide/template-engines) for full templating experience. Example of the structure: * πŸ“ **src** * πŸ“ **components** * πŸ“„ Button.html * πŸ“ **pages** * πŸ“ **nested** * πŸ“„ index.html * πŸ“„ index.html * πŸ“„ about.html ## Template Engines Today frontend tools are awesome, but the good old template engines don't get enough love anymore. Vituum tries to change this by supporting template engines in Vite.Let's go *Vite* with the templates! **Twig**, **Liquid**, **Pug**, **Nunjucks**, **Handlebars**, **Latte** - there are a bunch of them! Template engines are great for fast prototyping and preparing templates fast for PHPΒ backend frameworks like Symfony, Laravel or Nette. Example of the structure: * πŸ“ **src** * πŸ“ **layouts** * πŸ“„ Layout.twig * πŸ“ **pages** * πŸ“ **nested** * πŸ“„ index.twig * πŸ“„ index.json * πŸ“„ about.twig Learn more how to use template engines in Vituum [here](/guide/template-engines). ## Project structure Pre-defined optional structure for your template files. You can always change the structure to your own liking. * πŸ“ **public** - place for static files and dist files * πŸ“ **src** * πŸ“ **assets** - your static files as `.png`, `.svg` * πŸ“ **data** - your `.json` data used in templates * πŸ“ **emails** - your email template files * πŸ“ **scripts** - your script files as `.js`, `.ts` * πŸ“ **styles** - your styles files as `.css`, `.scss` * πŸ“ **components** - your template files as `.twig`, `.latte` * πŸ“ **layouts** - your template layout files as `.twig`, `.latte` * πŸ“ **pages** - your pages as `.html`, you can also nest or define page as `.json` or `.twig`, `.latte` and other template engines ## Imports In vanilla `css` and `js` you can import one file at a time. Globs like `*.css` or `*.js` are not possible. To help import multiple files automatically, **Vituum** uses internal plugin which adds all file imports in the directories into a single file. This is great if you have a complex project with a lot of styles or scripts files. All filetypes are supported, so you can use this also with `.css`, `.less`, `.scss` or `.js`, `.ts` or add your own via [config](/config/main-options#imports). Example of the structure: * πŸ“ **src** * πŸ“ **styles** * πŸ“ **Components** * πŸ“„ +.css * πŸ“„ Button.css * πŸ“„ Badge.css * πŸ“„ main.css ```css /* +.css */ @import "Button.css"; @import "Badge.css"; ``` ```css /* main.css */ @import "Components/+.css"; ``` ## Email Templates Writing email templates was always tricky. **Vituum** tries to make it easier for you. * With [@vituum/vite-plugin-juice](/plugins/juice) plugin you can write styles in **PostCSS** or any **pre-processor** you want. Everything will be inlined to html via **[Juice](https://github.com/Automattic/juice)**. * Html can be written with any [Template Engine](/guide/template-engines), including **PostHTML** or in plain HTML. * You can even use TailwindCSS or send your email for test via [@vituum/vite-plugin-send](/plugins/send) Learn more about [Email Templates here](/guide/email-templates). ## Other use Don't need template engines? You just want to write a **Vue** or **React** app? **Sure no problem, we do too!** **Vituum** is a set of plugins for **Vite**. So you can use other plugins like **PostCSS** or **TailwindCSS** in your project, or any of the internal plugins! Learn more on [Plugins page](/plugins/). Or go see all examples of usage [here](/guide/#trying-vituum-online). --- --- url: /plugins/concat.md --- # Concat *[@vituum/vite-plugin-concat](https://github.com/vituum/vite-plugin-concat)* Vite plugin for concatenating files together, handy especially for old projects that used gulp-concat or grunt-concat for concatenating `.js` files together. Automatically concatenates all `import './paths'` together into single file, additionally you can provide glob of files which should be also concated into single file via `files` option. ## Install **npm** ```bash npm i @vituum/vite-plugin-concat --save-dev ``` **yarn** ```bash yarn add @vituum/vite-plugin-concat -D ``` ## Config ```javascript import concat from '@vituum/vite-plugin-concat' export default { plugins: [concat({ input: ['main.js'] })] } ``` ## Options ### input * **Type:** `string[]` * **Default:** `[]` Determinates which input files should be processed by concat plugin. ### files * **Type:** `{[key: string]: string[]}` * **Default:** `{}` Additional files that should be concated together inside input file, eg. `{ 'main.js': ['src/scripts/**'] }` --- --- url: /config.md --- # Configuring Vituum **Vituum** needs to be added as a plugin in `vite.config.js` inside a project root. You can also use `.mjs`, `.ts`, learn more about [Vite config](https://vitejs.dev/config/). The most basic config file looks like this: ```js import vituum from 'vituum' export default { plugins: [vituum()] } ``` This adds basic [features](/guide/features) like multi-page support and imports. To add more features, you will need to define additional [plugins](/plugins/). Here is an example of usage with **LiquidJS** and **TailwindCSS** ```js import vituum from 'vituum' import liquid from '@vituum/vite-plugin-liquid' import tailwindcss from '@vituum/vite-plugin-tailwindcss' export default { plugins: [ vituum(), liquid(), tailwindcss() ] } ``` You can also choose to not use Vituum and only use its plugins, that's ok too if you don't need multi-page support and other core features. --- --- url: /plugins/css-inline.md --- # CSS Inline *[@vituum/vite-plugin-css-inline](https://www.npmjs.com/package/@vituum/vite-plugin-css-inline)* Adds support for inlining your `css` files to `html`. It's handy for creating email templates. Learn more about that [here](/guide/features#email-templates). See library [docs](https://github.com/Stranger6667/css-inline/tree/master/bindings/javascript) for more info about **css-inline**. > This is a faster alternative to [Juice](/plugins/juice) ## Install **npm** ```bash npm i @vituum/vite-plugin-css-inline --save-dev ``` **yarn** ```bash yarn add @vituum/vite-plugin-css-inline -D ``` ## Config ```javascript import cssInline from '@vituum/vite-plugin-css-inline' export default { plugins: [cssInline()] } ``` ## Options ### paths * **Type:** `string[]` * **Default:** `['src/pages/email']` Paths in which `html` files should be processed with [Juice](https://github.com/Automattic/juice) ### tables * **Type:** `boolean` * **Default:** `true` Whenever to add default attributes `border="0" cellpadding="0" cellspacing="0"` to every table. ### doctype * **Type:** `string` * **Default:** `` Default doctype to use, replaces `` from your `.html` with your doctype to use in emails. ### postcss.customProperties * **Type:** `pluginOptions` * **Default:** `{ preserve: false }` See all options [here](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-properties) ### postcss.processOptions * **Type:** `ProcessOptions` * **Default:** `undefined` See all options [here](https://postcss.org/api/#processor-process) ### postcss.plugins * **Type:** `ProcessOptions` * **Default:** `undefined` Here you can add additional [PostCSS plugins](https://github.com/postcss/postcss-load-config/blob/main/README.md#array). ### options * **Type:** `Object` * **Default:** `{}` Additional options for Juice. Learn more about Juice options [here](https://github.com/Stranger6667/css-inline/tree/master/bindings/javascript#configuration). --- --- url: /guide/email-templates.md --- # Email Templates To write email templates in Vite, you should start by adding following plugins in your `vite.config.js`, for templates in this example we use [PostHTML](/plugins/posthtml), but you can use any [Template Engine](/guide/template-engines) you want. ```javascript import vituum from 'vituum' import postcss from '@vituum/vite-plugin-postcss' import posthtml from '@vituum/vite-plugin-posthtml' import juice from '@vituum/vite-plugin-css-inline' import send from '@vituum/vite-plugin-send' export default { plugins: [ vituum(), postcss(), posthtml({ root: './src/emails' }), cssInline(), send() ] } ``` Now add your `index.html` to `/src/pages/email` ```html ``` And your `layout.html` should look like this. ```html
Vituum Emails
``` Now, since we're using [@vituum/vite-plugin-postcss](/plugins/postcss) (you can also use [lightningcss](https://vite.dev/config/shared-options#css-lightningcss)), we can use modern syntax in `/src/emails/main.css`. You can even switch this with [@vituum/vite-plugin-tailwindcss](/plugins/tailwindcss) or [@tailwindcss/vite](https://www.npmjs.com/package/@tailwindcss/vite) and use TailwindCSS classes. All CSS will be inlined into `html` via `css-inline`. You can write your emails much more easier, use modern syntax, split your email into components etc. Lastly, if you want to test your email, add an `.env` file to your project with env variables for [@vituum/vite-plugin-send](/plugins/send), or add them via config. After that you can add `?send` in your browser URL and a test email will be sent to you. We also recommend uploading your images somewhere, so that they can load in your email. Find full example of using Vituum with Juice on [Trying Vituum Online](/guide/#trying-vituum-online). --- --- url: /guide.md --- # Getting Started ## Overview Vituum is a mix of words **Vite** *(French word for "quick")* and **Tuum** *(Estonian word for "core")* It's a set of plugins for **Vite**, the full list can be found on [Plugins page](/plugins/). ## Get started Already using preview version of Vituum 0.0.x? [Learn more](/guide/migrating-1-0) how to migrate to 1.0. ```bash $ npm create vite@latest $ npm i vituum --save-dev ``` Then add Vituum to your [Vite config](https://vitejs.dev/config/), this adds basic multi-page `.html` support in `src/pages`. Add more functionality, template engines and more with [Vituum Plugins](/plugins/). ```javascript import vituum from 'vituum' export default { plugins: [ vituum() ] } ``` And start Vite. Or build your project, see [Vite docs](https://vitejs.dev/guide/cli.html) for more info. ```bash $ npx vite ``` You can learn more about how to use **Vituum** in the examples bellow. ## Trying Vituum Online You can also try Vituum online on [StackBlitz](https://stackblitz.com/). ### Basic * [vituum](https://stackblitz.com/github/vituum/vituum/tree/main/examples/vanilla) * [vituum + posthtml](https://stackblitz.com/github/vituum/vituum/tree/main/examples/posthtml) * [vituum + postcss](https://stackblitz.com/github/vituum/vituum/tree/main/examples/postcss) * [vituum + less](https://stackblitz.com/github/vituum/vituum/tree/main/examples/less) * [vituum + sass](https://stackblitz.com/github/vituum/vituum/tree/main/examples/sass) * [vituum + juice](https://stackblitz.com/github/vituum/vituum/tree/main/examples/juice) ### Templates * [vituum + twig](https://stackblitz.com/github/vituum/vituum/tree/main/examples/twig) * [vituum + latte](https://stackblitz.com/github/vituum/vituum/tree/main/examples/latte) * [vituum + liquid](https://stackblitz.com/github/vituum/vituum/tree/main/examples/liquid) * [vituum + nunjucks](https://stackblitz.com/github/vituum/vituum/tree/main/examples/nunjucks) * [vituum + handlebars](https://stackblitz.com/github/vituum/vituum/tree/main/examples/handlebars) * [vituum + pug](https://stackblitz.com/github/vituum/vituum/tree/main/examples/pug) ### CSS * [vituum + tailwindcss](https://stackblitz.com/github/vituum/vituum/tree/main/examples/tailwindcss) * [vituum + winduum](https://stackblitz.com/github/vituum/vituum/tree/main/examples/winduum) * [vituum + openprops](https://stackblitz.com/github/vituum/vituum/tree/main/examples/openprops) * [vituum + bootstrap](https://stackblitz.com/github/vituum/vituum/tree/main/examples/bootstrap) * [vituum + bulma](https://stackblitz.com/github/vituum/vituum/tree/main/examples/bulma) All examples can be found on [GitHub](https://github.com/vituum/vituum/tree/main/examples). --- --- url: /plugins/handlebars.md --- # Handlebars *[@vituum/vite-plugin-handlebars](https://github.com/vituum/vite-plugin-handlebars)* ```handlebars ``` See [docs](https://handlebarsjs.com/) for more info about the syntax ## Install **npm** ```bash npm i @vituum/vite-plugin-handlebars --save-dev ``` **yarn** ```bash yarn add @vituum/vite-plugin-handlebars -D ``` ## Config ```javascript import handlebars from '@vituum/vite-plugin-handlebars' export default { plugins: [handlebars()] } ``` ## Options ### reload * **Type:** `boolean` or `Function` * **Default:** `true` Whenever to auto-reload browser window upon `hbs` or `json` file change. You can also provide function to filter upon which file a reload should occur. ### root * **Type:** `string` * **Default:** `null` Root is inherited from Vite `root` by default. But you can change this to path such as `'./src/'` or `'./src/templates'`, then you can use includes with paths defaulting to this directory. ### helpers * **Type:** `Object` * **Default:** `{}` Object of named helper functions to use, see Handlebars [docs](https://handlebarsjs.com/api-reference/helpers.html) for more info. ### partials.directory * **Type:** `string` * **Default:** `null` Root directory for partials. Directory is inherited from plugin `root` by default. ### partials.extname * **Type:** `boolean` * **Default:** `true` Whenever to use ext-name in partial path like this `"path/to/partial.hbs` ### data * **Type:** `string` * **Default:** `['src/data/**/*.json']` Path to additional data provided with json file. Can be a file, or a glob like this `/path/to/*.jsom`. ### globals * **Type:** `Object` * **Default:** `{}` Other global data to use. Can be `Object` or `function` returning object, or combination of both. ### ignoredPaths * **Type:** `string[]` * **Default:** `[]` Which paths should be ignored from processing as TwigJS. ### formats * **Type:** `string[]` * **Default:** `['hbs', 'json.hbs', 'json']` Which ext-names should be processed by the plugin. ### options.compileOptions * **Type:** `Object` * **Default:** `{}` Additional Handlebars compileOptions, see Handlebars [docs](https://handlebarsjs.com/api-reference/compilation.html) for more info. ### options.runtimeOptions * **Type:** `Object` * **Default:** `{}` Additional Handlebars runtimeOptions, see Handlebars [docs](https://handlebarsjs.com/api-reference/runtime-options.html) for more info. --- --- url: /plugins/imports.md --- # Imports *Internal Vituum Plugin* Learn more about this plugin on [Features](/guide/features#⬇️-imports) page. ## Install **npm** ```bash npm i vituum --save-dev ``` **yarn** ```bash yarn add vituum -D ``` ## Config ```javascript import vituum from 'vituum' export default { plugins: [vituum()] } ``` ### Using separately ```javascript import imports from 'vituum/plugins/imports.js' export default { plugins: [imports()] } ``` ## Options ## paths * **Type:** `string[]` * **Default:** `['./src/styles/*/**', './src/scripts/*/**']` Paths where auto-imports should be resolved. ## extnamePattern.styles * **Type:** `RegExp` * **Default:** `/.(css|less|scss|pcss)$/` Types of files that should be resolved as styles ## extnamePattern.scripts * **Type:** `RegExp` * **Default:** `/.(js|mjs|ts)$/` Types of files that should be resolved as scripts ## filenamePattern * **Type:** `Object` * **Default:** `{'+.css': 'src/styles', '+.js': 'src/scripts'}` Filename for file with imports paths and where it should be applied. Path can be also `string[]` of paths. --- --- url: /plugins/juice.md --- # Juice *[@vituum/vite-plugin-juice](https://www.npmjs.com/package/@vituum/vite-plugin-juice)* Adds support for inlining your `css` files to `html`. It's handy for creating email templates. Learn more about that [here](/guide/features#email-templates). See library [docs](https://github.com/Automattic/juice) for more info about **Juice**. > Juice is dependency heavy and slow, consider using [css-inline](/plugins/css-inline) instead as a faster alternative. ## Install **npm** ```bash npm i @vituum/vite-plugin-juice --save-dev ``` **yarn** ```bash yarn add @vituum/vite-plugin-juice -D ``` ## Config ```javascript import juice from '@vituum/vite-plugin-juice' export default { plugins: [juice()] } ``` ## Options ### paths * **Type:** `string[]` * **Default:** `['src/pages/email']` Paths in which `html` files should be processed with [Juice](https://github.com/Automattic/juice) ### tables * **Type:** `boolean` * **Default:** `true` Whenever to add default attributes `border="0" cellpadding="0" cellspacing="0"` to every table. ### doctype * **Type:** `string` * **Default:** `` Default doctype to use, replaces `` from your `.html` with your doctype to use in emails. ### postcss.processOptions * **Type:** `ProcessOptions` * **Default:** `undefined` See all options [here](https://postcss.org/api/#processor-process) ### postcss.plugins * **Type:** `ProcessOptions` * **Default:** `undefined` Here you can add additional [PostCSS plugins](https://github.com/postcss/postcss-load-config/blob/main/README.md#array). ### options * **Type:** `Object` * **Default:** `{}` Additional options for Juice. Learn more about Juice options [here](https://github.com/Automattic/juice#options). --- --- url: /plugins/latte.md --- # Latte *[@vituum/vite-plugin-latte](https://github.com/vituum/vite-plugin-latte)* * Requires [PHP (8.x)](https://www.php.net/) or [Docker PHP (8.x)](https://hub.docker.com/_/php) to run ```handlebars or ``` See [docs](https://latte.nette.org/en/) for more info about the syntax ## Install **npm** ```bash npm i @vituum/vite-plugin-latte --save-dev ``` **yarn** ```bash yarn add @vituum/vite-plugin-latte -D ``` ## Config ```javascript import vituum from 'vituum' import latte from '@vituum/vite-plugin-latte' export default { plugins: [vituum(), latte()] } ``` ## Options ### reload * **Type:** `boolean` or `Function` * **Default:** `true` Whenever to auto-reload browser window upon `latte` or `json` file change. You can also provide function to filter upon which file a reload should occur. ### root * **Type:** `string` * **Default:** `null` Root is inherited from Vite `root` by default. But you can change this to path such as `'./src/'` or `'./src/templates'`, then you can use includes with paths defaulting to this directory. ### filters * **Type:** `Object` * **Default:** `{}` Object of named filters to use. Can be function or string providing path to `.php` or `.js` (faster than function) file. See examples [here](https://github.com/vituum/vite-plugin-latte/tree/main/latte) or official docs [here](https://latte.nette.org/en/extending-latte#toc-filters). ### functions * **Type:** `Object` * **Default:** `{}` Object of named functions to use. Can be function or string providing path to `.php` or `.js` (faster than function) file. See examples [here](https://github.com/vituum/vite-plugin-latte/tree/main/latte) or official docs [here](https://latte.nette.org/en/extending-latte#toc-functions). ### tags * **Type:** `Object` * **Default:** `{}` Object of named tags to use. Only a string providing path to `.php` file is possible. See official docs [here](https://latte.nette.org/en/extending-latte#toc-tags). ### data * **Type:** `string` * **Default:** `['src/data/**/*.json']` Path to additional data provided with json file. Can be a file, or a glob like this `/path/to/*.jsom`. ### globals * **Type:** `Object` * **Default:** `{}` Other global data to use. Can be `Object` or `function` returning object, or combination of both. ### ignoredPaths * **Type:** `string[]` * **Default:** `[]` Which paths should be ignored from processing as TwigJS. ### formats * **Type:** `string[]` * **Default:** `['latte', 'json.latte', 'json']` Which ext-names should be processed by the plugin. ### bin * **Type:** `string` * **Default:** `php` Which binary should be used for processing `latte` files, you can also set `docker` but it's slower. ### renderTransformedHtml * **Type:** `Function` * **Default:** `(path) => false` Determines which path should be rendered as transformedHtml from Vite, otherwise `php` is loading your file directly from disk and not from transformed stream. You might need this if you need to transform your file via Vite before `latte` renders your file. --- --- url: /plugins/liquid.md --- # Liquid *[@vituum/vite-plugin-liquid](https://github.com/vituum/vite-plugin-liquid)* ```twig ``` See official [docs](https://liquidjs.com/) for more info about the syntax ## Install **npm** ```bash npm i @vituum/vite-plugin-liquid --save-dev ``` **yarn** ```bash yarn add @vituum/vite-plugin-liquid -D ``` ## Config ```javascript import vituum from 'vituum' import liquid from '@vituum/vite-plugin-liquid' export default { plugins: [vituum(), liquid()] } ``` ## Options ### reload * **Type:** `boolean` or `Function` * **Default:** `true` Whenever to auto-reload browser window upon `liquid` or `json` file change. You can also provide function to filter upon which file a reload should occur. ### root * **Type:** `string` * **Default:** `null` Root is inherited from Vite `root` by default. But you can change this to path such as `'./src/'` or `'./src/templates'`, then you can use includes with paths defaulting to this directory. ### filters * **Type:** `Object` * **Default:** `{}` Object of named filter functions to use, see LiquidJS [docs](https://liquidjs.com/tutorials/register-filters-tags.html#Register-Filters) for more info. ### tags * **Type:** `Function[]` * **Default:** `[]` Array of functions that extend LiquidJS with custom tag, see LiquidJS [docs](https://liquidjs.com/tutorials/register-filters-tags.html#Register-Tags) for more info. ### data * **Type:** `string | string[]` * **Default:** `''` Path to additional data provided with json file. Can be a file, or a glob like this `/path/to/*.jsom`. ### globals * **Type:** `Object` * **Default:** `{}` Other global data to use. Can be `Object` or `function` returning object, or combination of both. ### ignoredPaths * **Type:** `string[]` * **Default:** `[]` Which paths should be ignored from processing as LiquidJS. ### formats * **Type:** `string[]` * **Default:** `['liquid', 'json.liquid', 'json']` Which ext-names should be processed by the plugin. ### options.liquidOptions * **Type:** `Object` * **Default:** `{}` Additional LiquidJS options, see LiquidJS [docs](https://liquidjs.com/api/interfaces/LiquidOptions.html) for more info. ### options.renderOptions * **Type:** `Object` * **Default:** `{}` Additional render options, see LiquidJS [docs](https://liquidjs.com/) for more info. ### options.renderFileOptions * **Type:** `Object` * **Default:** `{}` Additional renderFile options, see LiquidJS [docs](https://liquidjs.com/) for more info. --- --- url: /config/main-options.md --- # Main Options These are the main **Vituum** options that can be used in the main plugin. ## input * **Type:** `string[]` * **Default:** `['./src/styles/*.{css,pcss,scss,sass,less,styl,stylus}', './src/scripts/*.{js,ts,mjs}']` Additional paths that are added in `build.rollupOptions.input`, change this mainly if you want to change paths for you styles and scripts or to add other paths for templates. Default paths for `build.rollupOptions.input` are following, so if you want to change them completely, change them in `build.rollupOptions.input`. ```javascript // build.rollupOptions.input [ './src/emails/*.{json,latte,twig,liquid,njk,hbs,pug,html}', './src/pages/**/*.{json,latte,twig,liquid,njk,hbs,pug,html}', '!./src/pages/**/*.{latte,twig,liquid,njk,hbs,pug,html}.json' ] ``` ## formats * **Type:** `string[]` * **Default:** `'./src'` Determines which extname formats are supported inside `build.rollupOptions.input` and renamed to `.html`. ## pages See [Pages Plugin](/plugins/pages) for more info about options. ## imports See [Imports Plugin](/plugins/imports) for more info about options. --- --- url: /guide/migrating-1-0.md --- # Migrating to 1.0 1.0 is a complete rewrite and various functions were removed or simplified * Vituum is no longer defined as a wrapper around Vite, but as a Vite plugin * PostCSS plugins are no longer included by default, to add them use [@vituum/vite-plugin-postcss](/plugins/postcss) * Various main config options were removed, see [config](/config/main-options) for more details what remained * `src/views` directory was changed to `src/pages`, but you can still use views by changing it in the config (see [main-options](/config/main-options.html#input) and [pages](/plugins/pages.html#dir)) * `vituum` build command was removed in favour of building directly with Vite * Integrations were removed, and everything is a Vite plugin now * Defining template with `