README
kirbyup
Take a look into Kirby's pluginkit repository for an example setup.
The fastest and leanest way to bundle your Kirby Panel plugins. No configuration necessary.
Key Features
- đ Lightweight, robust and tested
- âĄī¸ Fast compilation with Vite/esbuild
- đ Watch mode
- *ī¸âŖ
kirbyup.import
to auto-import blocks & fields - đ PostCSS support
- đ§ Path resolve aliases
- đ Env variables support
- đĻ Extendable configuration with
kirbyup.config.js
Requirements
- Node 14+ (Node 16 recommended)
âšī¸ When using kirbyup with
npx
, npm 7+ is required. Previous versions don't pass cli arguments to the package invoked. npm 7 is bundled from Node 16 onwards.
Get Started Right Away
âĻ With one of the following Panel plugin kits:
eslint-and-prettier
(recommended)tailwindcss
- Kirby's default
pluginkit
Installation
If you want to use kirbyup right away, there is no need to install it. Simply call it with npx
:
{
"scripts": {
"dev": "npx -y kirbyup src/index.js --watch",
"build": "npx -y kirbyup src/index.js"
}
}
If
npx
doesn't use the latest kirbyup version, although it is available, runnpx -y kirbyup@latest
instead or delete the~/.npm/_npx
cache folder.
While kirbyup will stay backwards compatible, exact build reproducibility may be of importance to you. If so, I recommend to target a specific package version, rather than using npx
. Install kirbyup with a package manager of your choice locally to your project:
npm i kirbyup --save-dev
Example package configuration:
{
"scripts": {
"dev": "kirbyup src/index.js --watch",
"build": "kirbyup src/index.js"
},
"devDependencies": {
"kirbyup": "latest"
}
}
Global installation is supported as well, but not recommended.
Usage
Development
Rebuild the Panel plugin on any file changes:
kirbyup src/index.js --watch
You can also specify the directories to be watched. By default, if no path is specified, kirbyup watches the directory specified by the input file (src
for the example above).
kirbyup src/index.js --watch src
You can specify more than a single directory:
kirbyup src/index.js --watch src --watch libs
Production
kirbyup src/index.js
The final panel plugin will be bundled, minified, and written into the current directory as ./index.js
.
Built-in Features
PostCSS
If the project contains a valid PostCSS config (any format supported by postcss-load-config, e.g. postcss.config.js
), it will be automatically applied to all imported CSS.
If no configuration file is found, kirbyup will apply two PostCSS plugins which the Kirby Panel uses as well to let you embrace the same functionality within your Panel plugins. The following PostCSS transforms are applied by kirbyup:
- postcss-logical lets you use logical, rather than physical, direction and dimension mappings in CSS, following the CSS Logical Properties and Values specification.
- postcss-dir-pseudo-class lets you style by directionality using the
:dir()
pseudo-class in CSS, following the Selectors specification. It gives you the same syntax Kirby uses for full compatibility with RTL localizations of the Panel.
Path Resolve Aliases
Import certain modules more easily by using the ~/
path alias. It will resolve to the directory of your input file, for example src
when building kirbyup src/index.js
.
Now, given a deeply nested component, instead of using relative paths when importing like so:
// Inside deeply nested module
import someUtility from '../../utils'
You can use the alias:
import someUtility from '~/utils'
âšī¸ You can use
@/
as path alias as well.
Auto-Import Blocks and Fields
If you find yourself in the situation of needing to import multiple blocks or fields into your Panel plugin, you can use the kirbyup kirbyup.import
function to ease the process.
Before:
import Foo from './components/blocks/Foo.vue'
import Bar from './components/blocks/Bar.vue'
import Maps from './components/blocks/Maps.vue'
window.panel.plugin('kirbyup/example', {
blocks: {
foo: Foo,
bar: Bar,
maps: Maps
}
})
After:
import { kirbyup } from 'kirbyup/plugin'
window.panel.plugin('kirbyup/example', {
blocks: kirbyup.import('./components/blocks/*.vue')
})
Env Variables
kirbyup exposes env variables on the special import.meta.env
object. Some built-in variables are available in all cases:
import.meta.env.MODE
: {development
|production
} the mode kirbyup is running in.import.meta.env.PROD
: {boolean} whether kirbyup is running in production.import.meta.env.DEV
: {boolean} whether kirbyup is running in development (always the opposite ofimport.meta.env.PROD
)
During production, these env variables are statically replaced. It is therefore necessary to always reference them using the full static string. For example, dynamic key access like import.meta.env[key]
will not work.
Files .env
kirbyup (thanks to Vite) uses dotenv to load additional environment variables from the following files in your plugin's root directory:
.env # loaded in all cases
.env.local # loaded in all cases, ignored by git
.env.[mode] # only loaded in specified mode
.env.[mode].local # only loaded in specified mode, ignored by git
Loaded env variables are also exposed to your source code via import.meta.env
.
To prevent accidentally leaking env variables for distribution, only variables prefixed with KIRBYUP_
or VITE_
are exposed to your processed code. Take the following file as an example:
DB_PASSWORD=foobar
KIRBYUP_SOME_KEY=123
Only KIRBYUP_SOME_KEY
will be exposed as import.meta.env.VITE_SOME_KEY
to your plugin's source code, but DB_PASSWORD
will not.
kirbyup.config.js
Extendable Configuration With Create a kirbyup.config.js
or kirbyup.config.ts
configuration file the root-level of your project to customize kirbyup.
import { resolve } from 'path'
import { defineConfig } from 'kirbyup'
export default defineConfig({
alias: {
'#deep/': `${resolve(__dirname, 'src/deep')}/`
},
extendViteConfig: {
build: {
lib: {
name: 'myPlugin'
}
}
}
})
alias
When aliasing to file system paths, always use absolute paths. Relative alias values will be used as-is and will not be resolved into file system paths.
extendViteConfig
You can build upon the defaults kirbup uses and extend the Vite configuration with custom plugins etc.
For a complete list of options, take a look at the Vite configuration options.
Options
Inspect all available options with
kirbyup --help
.
--out-dir
The output directory to save the processed code into. Defaults to the current working directory.
--watch
Sets the watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat --watch
for multiple paths.
Credits
License
MIT License Š 2021 Johann Schopplich