3.1.5 ā€¢ Published 12 days ago

kirbyup v3.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

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

Requirements

  • Node 16 (active LTS) or newer

Get Started Right Away

ā€¦ With one of the following Panel plugin kits:

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",
    "serve": "npx -y kirbyup serve src/index.js",
    "build": "npx -y kirbyup src/index.js"
  }
}

If npx doesn't use the latest kirbyup version, although it is available, run npx -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",
    "serve": "kirbyup serve src/index.js",
    "build": "kirbyup src/index.js"
  },
  "devDependencies": {
    "kirbyup": "latest"
  }
}

Global installation is supported as well, but not recommended.

Usage

Development

Start a development server for the Panel plugin:

ā„¹ļø This feature requires Kirby v3.7.4+.

kirbyup serve src/index.js

This creates ./index.dev.mjs, telling Kirby to load the development version of the plugin from the dev server started by kirbyup serve, enhanced by features like hot module replacement and auto-reload.

If you prefer the watch mode to build a development bundle of the final Panel plugin or develop in an older version of Kirby (prior to 3.7.4), run:

kirbyup src/index.js --watch

Production

kirbyup src/index.js

The final panel plugin will be bundled, minified, and written into the current directory as ./index.js and ./index.css.

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:

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 of import.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.

.env Files

kirbyup (thanks to Vite) uses dotenv to load additional environment variables from the .env and .env.local files in your plugin's root directory.

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.

Extendable Configuration With kirbyup.config.js

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/config'

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 and kirbyup serve --help.

kirbyup <input>

--out-dir <dir>

The output directory to save the processed code into. Defaults to the current working directory.

--watch [path]

Enables watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat --watch for multiple paths.

kirbyup serve <input>

--port <port>

The port for the development server to run on. Defaults to 5177.

--out-dir <dir>

The output directory where the plugin file read by Kirby is saved. Defaults to the project root.

--watch <path>

Specifies additional files that should be watched for changes, with changes causing the page to reload. Repeat --watch for multiple paths.

šŸ’” By default, kirbyup will watch all PHP files (./**/*.php) in the plugin directory and reload the page if it detects changes. Using --watch to set your own path overrides this setting, so you need to add the PHP glob explicitly if you want to keep the behavior: --watch ./my/files/* --watch ./**/*.php

--no-watch

Disables the default behavior of watching all PHP files for changes.

Credits

  • Vite by Evan You and all of its contributors.
  • EGOIST for his inspirational work on tsup.

License

MIT License Ā© 2021-2022 Johann Schopplich

MIT License Ā© 2022 Jonas Kuske

4.0.0-alpha.1

12 days ago

3.1.5

2 months ago

3.1.4

3 months ago

3.1.3

3 months ago

3.1.2

3 months ago

3.1.1

3 months ago

3.1.0-beta.0

5 months ago

3.1.0

5 months ago

3.0.2

6 months ago

3.0.1

8 months ago

2.2.1

11 months ago

3.0.0

10 months ago

2.2.1-beta.0

11 months ago

3.0.0-beta.0

11 months ago

2.2.0-beta.0

1 year ago

2.2.0-beta.1

1 year ago

2.2.0

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

2 years ago

2.1.0-beta.1

2 years ago

2.1.0-beta.2

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.0.2-beta.0

2 years ago

2.1.0-beta.0

2 years ago

1.2.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.0.0-beta.0

2 years ago

0.24.1

2 years ago

0.24.0

2 years ago

0.23.0

2 years ago

0.22.3

2 years ago

0.22.2

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.21.0

2 years ago

0.20.1

2 years ago

0.21.1

2 years ago

0.20.0

3 years ago

0.19.0

3 years ago

0.19.1

3 years ago

0.17.2

3 years ago

0.17.3

3 years ago

0.14.0

3 years ago

0.15.0

3 years ago

0.14.1

3 years ago

0.16.0

3 years ago

0.15.1

3 years ago

0.17.0

3 years ago

0.15.2

3 years ago

0.18.0

3 years ago

0.17.1

3 years ago

0.13.0

3 years ago

0.12.0

3 years ago

0.12.1

3 years ago

0.11.1

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.10.1

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.5

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago