kirbyup 1.3.0 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -1
- package/README.md +37 -23
- package/dist/cli.mjs +24 -15
- package/dist/config.d.ts +6 -0
- package/dist/config.mjs +5 -0
- package/dist/index.d.ts +5 -34
- package/dist/index.mjs +3 -1
- package/dist/plugin.mjs +7 -4
- package/dist/{chunks/index.mjs → shared/kirbyup.275c66c6.mjs} +171 -52
- package/dist/types-02ae296f.d.ts +36 -0
- package/package.json +35 -15
package/LICENSE
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021-2022 Johann Schopplich
|
|
3
|
+
Copyright (c) 2021-2022 Johann Schopplich <https://github.com/johannschopplich>
|
|
4
|
+
Copyright (c) 2022 Jonas Kuske <https://github.com/jonaskuske>
|
|
4
5
|
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The fastest and leanest way to bundle your Kirby Panel plugins. No configuration
|
|
|
8
8
|
|
|
9
9
|
- 🍂 Lightweight, robust and tested
|
|
10
10
|
- ⚡️ Fast compilation with Vite/esbuild
|
|
11
|
-
-
|
|
11
|
+
- 🔄 Hot Module Replacement and watch mode
|
|
12
12
|
- \*️⃣ `kirbyup.import` to [auto-import blocks & fields](#auto-import-blocks-and-fields)
|
|
13
13
|
- 🎒 [PostCSS support](#postcss)
|
|
14
14
|
- 🧭 [Path resolve aliases](#path-resolve-aliases)
|
|
@@ -36,7 +36,7 @@ If you want to use kirbyup right away, there is no need to install it. Simply ca
|
|
|
36
36
|
```json
|
|
37
37
|
{
|
|
38
38
|
"scripts": {
|
|
39
|
-
"dev": "npx -y kirbyup src/index.js
|
|
39
|
+
"dev": "npx -y kirbyup serve src/index.js",
|
|
40
40
|
"build": "npx -y kirbyup src/index.js"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -55,7 +55,7 @@ Example package configuration:
|
|
|
55
55
|
```json
|
|
56
56
|
{
|
|
57
57
|
"scripts": {
|
|
58
|
-
"dev": "kirbyup src/index.js
|
|
58
|
+
"dev": "kirbyup serve src/index.js",
|
|
59
59
|
"build": "kirbyup src/index.js"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
@@ -70,23 +70,13 @@ Global installation is supported as well, but not recommended.
|
|
|
70
70
|
|
|
71
71
|
### Development
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
Start a development server for the Panel plugin:
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
|
-
kirbyup src/index.js
|
|
76
|
+
kirbyup serve src/index.js
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
kirbyup src/index.js --watch src
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
You can specify more than a single directory:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
kirbyup src/index.js --watch src --watch libs
|
|
89
|
-
```
|
|
79
|
+
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.
|
|
90
80
|
|
|
91
81
|
### Production
|
|
92
82
|
|
|
@@ -94,7 +84,7 @@ kirbyup src/index.js --watch src --watch libs
|
|
|
94
84
|
kirbyup src/index.js
|
|
95
85
|
```
|
|
96
86
|
|
|
97
|
-
The final panel plugin will be bundled, minified, and written into the current directory as `./index.js`.
|
|
87
|
+
The final panel plugin will be bundled, minified, and written into the current directory as `./index.js` and `./index.css`.
|
|
98
88
|
|
|
99
89
|
## Built-in Features
|
|
100
90
|
|
|
@@ -194,7 +184,7 @@ Create a `kirbyup.config.js` or `kirbyup.config.ts` configuration file the root-
|
|
|
194
184
|
|
|
195
185
|
```js
|
|
196
186
|
import { resolve } from 'path'
|
|
197
|
-
import { defineConfig } from 'kirbyup'
|
|
187
|
+
import { defineConfig } from 'kirbyup/config'
|
|
198
188
|
|
|
199
189
|
export default defineConfig({
|
|
200
190
|
alias: {
|
|
@@ -222,15 +212,37 @@ For a complete list of options, take a look at the [Vite configuration options](
|
|
|
222
212
|
|
|
223
213
|
## Options
|
|
224
214
|
|
|
225
|
-
> Inspect all available options with `kirbyup --help`.
|
|
215
|
+
> Inspect all available options with `kirbyup --help` and `kirbyup serve --help`.
|
|
216
|
+
|
|
217
|
+
### `kirbyup <input>`
|
|
226
218
|
|
|
227
|
-
|
|
219
|
+
##### `--out-dir <dir>`
|
|
228
220
|
|
|
229
221
|
The output directory to save the processed code into. Defaults to the current working directory.
|
|
230
222
|
|
|
231
|
-
|
|
223
|
+
##### `--watch [path]`
|
|
224
|
+
|
|
225
|
+
Enables watch mode. If no path is specified, kirbyup watches the folder of the input file. Repeat `--watch` for multiple paths.
|
|
226
|
+
|
|
227
|
+
### `kirbyup serve <input>`
|
|
232
228
|
|
|
233
|
-
|
|
229
|
+
##### `--port <port>`
|
|
230
|
+
|
|
231
|
+
The port for the development server to run on. Defaults to `5177`.
|
|
232
|
+
|
|
233
|
+
##### `--out-dir <dir>`
|
|
234
|
+
|
|
235
|
+
The output directory where the plugin file read by Kirby is saved. Defaults to the project root.
|
|
236
|
+
|
|
237
|
+
##### `--watch <path>`
|
|
238
|
+
|
|
239
|
+
Specifies additional files that should be watched for changes, with changes causing the page to reload. Repeat `--watch` for multiple paths.
|
|
240
|
+
|
|
241
|
+
> 💡 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`
|
|
242
|
+
|
|
243
|
+
##### `--no-watch`
|
|
244
|
+
|
|
245
|
+
Disables the default behavior of watching all PHP files for changes.
|
|
234
246
|
|
|
235
247
|
## Credits
|
|
236
248
|
|
|
@@ -239,4 +251,6 @@ Sets the watch mode. If no path is specified, kirbyup watches the folder of the
|
|
|
239
251
|
|
|
240
252
|
## License
|
|
241
253
|
|
|
242
|
-
[MIT](./LICENSE) License © 2021 [Johann Schopplich](https://github.com/johannschopplich)
|
|
254
|
+
[MIT](./LICENSE) License © 2021-2022 [Johann Schopplich](https://github.com/johannschopplich)
|
|
255
|
+
|
|
256
|
+
[MIT](./LICENSE) License © 2022 [Jonas Kuske](https://github.com/jonaskuske)
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cac } from 'cac';
|
|
2
|
-
import { n as name, b as build, v as version, h as handleError } from './
|
|
2
|
+
import { n as name, b as build, s as serve, v as version, h as handleError } from './shared/kirbyup.275c66c6.mjs';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'node:fs/promises';
|
|
5
5
|
import 'pathe';
|
|
@@ -14,27 +14,36 @@ import 'postcss-dir-pseudo-class';
|
|
|
14
14
|
import 'consola';
|
|
15
15
|
import 'perfect-debounce';
|
|
16
16
|
import 'picocolors';
|
|
17
|
+
import 'vite-plugin-full-reload';
|
|
17
18
|
import 'zlib';
|
|
18
19
|
import 'util';
|
|
19
20
|
import 'unconfig';
|
|
20
21
|
import 'magic-string';
|
|
22
|
+
import 'detect-package-manager';
|
|
21
23
|
|
|
22
|
-
async function startCli(cwd = process.cwd(), argv = process.argv
|
|
24
|
+
async function startCli(cwd = process.cwd(), argv = process.argv) {
|
|
23
25
|
const cli = cac(name);
|
|
24
|
-
cli.command("
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
default:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
cwd,
|
|
31
|
-
...flags
|
|
32
|
-
});
|
|
33
|
-
if (file)
|
|
34
|
-
options.entry = file;
|
|
35
|
-
await build(options);
|
|
26
|
+
cli.command("<file>", "Compile the Kirby Panel plugin to index.js and index.css").option("-d, --out-dir <dir>", "Output directory", { default: cwd }).option(
|
|
27
|
+
"-w, --watch [path]",
|
|
28
|
+
"Watch for file changes. If no path is specified, the folder of the input file will be watched",
|
|
29
|
+
{ default: false }
|
|
30
|
+
).example("kirbyup src/index.js").example("kirbyup src/index.js --out-dir ~/kirby-site/site/plugins/demo").example("kirbyup src/index.js --watch src/**/*.{js,css} --watch assets/*\n").action(async (file, options) => {
|
|
31
|
+
await build({ cwd, entry: file, ...options });
|
|
36
32
|
});
|
|
37
|
-
cli.
|
|
33
|
+
cli.command("serve <file>", "Start development server with live reload").option("--no-watch", "Don't watch .php files for changes", { default: "\0" }).option("-w, --watch <path>", "Watch additional files", { default: "./**/*.php" }).option("-p, --port <number>", "Port for the development server", { default: 5177 }).option("-d, --out-dir <dir>", "Output directory").example("kirbyup serve src/index.js").example("kirbyup serve src/index.js --no-watch --port 3003").example("kirbyup serve src/index.js --watch snippets/*.php --watch templates/*.php\n").action(async (file, options) => {
|
|
34
|
+
const server = await serve({ cwd, entry: file, ...options });
|
|
35
|
+
const exitProcess = async () => {
|
|
36
|
+
try {
|
|
37
|
+
await server.close();
|
|
38
|
+
} finally {
|
|
39
|
+
process.exit();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
process.once("SIGINT", exitProcess);
|
|
43
|
+
});
|
|
44
|
+
cli.help(
|
|
45
|
+
(s) => s.map((msg) => ({ ...msg, body: msg.body.replace(" (default: \0)", "") }))
|
|
46
|
+
);
|
|
38
47
|
cli.version(version);
|
|
39
48
|
cli.parse(argv, { run: false });
|
|
40
49
|
await cli.runMatchedCommand();
|
package/dist/config.d.ts
ADDED
package/dist/config.mjs
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { B as BuildOptions, S as ServeOptions } from './types-02ae296f.js';
|
|
2
3
|
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
cwd?: string;
|
|
6
|
-
entry?: string;
|
|
7
|
-
outDir?: string;
|
|
8
|
-
watch?: boolean | string | Array<boolean | string>;
|
|
9
|
-
}
|
|
10
|
-
declare type ResolvedCliOptions = MarkRequired<CliOptions, 'cwd' | 'entry'>;
|
|
11
|
-
interface UserConfig {
|
|
12
|
-
/**
|
|
13
|
-
* Load from config files
|
|
14
|
-
* Set to `false` to disable
|
|
15
|
-
*/
|
|
16
|
-
configFile?: string | false;
|
|
17
|
-
/**
|
|
18
|
-
* Specifies an `Object`, or an `Array` of `Object`,
|
|
19
|
-
* which defines aliases used to replace values in `import` statements.
|
|
20
|
-
* With either format, the order of the entries is important,
|
|
21
|
-
* in that the first defined rules are applied first.
|
|
22
|
-
*/
|
|
23
|
-
alias?: AliasOptions;
|
|
24
|
-
/**
|
|
25
|
-
* Extends Vite's configuration. Will be merged with kirbyup's
|
|
26
|
-
* default configuration. Be careful what to extend.
|
|
27
|
-
*/
|
|
28
|
-
extendViteConfig?: InlineConfig;
|
|
29
|
-
}
|
|
4
|
+
declare function build(options: BuildOptions): Promise<void>;
|
|
5
|
+
declare function serve(options: ServeOptions): Promise<vite.ViteDevServer>;
|
|
30
6
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
declare function resolveOptions(options: CliOptions): Promise<ResolvedCliOptions>;
|
|
34
|
-
declare function build(_options: CliOptions): Promise<void>;
|
|
35
|
-
|
|
36
|
-
export { build, defineConfig, resolveOptions };
|
|
7
|
+
export { build, serve };
|
package/dist/index.mjs
CHANGED
|
@@ -2,13 +2,14 @@ import 'node:fs';
|
|
|
2
2
|
import 'node:fs/promises';
|
|
3
3
|
import 'pathe';
|
|
4
4
|
import 'vite';
|
|
5
|
-
export { b as build,
|
|
5
|
+
export { b as build, s as serve } from './shared/kirbyup.275c66c6.mjs';
|
|
6
6
|
import 'postcss-load-config';
|
|
7
7
|
import 'postcss-logical';
|
|
8
8
|
import 'postcss-dir-pseudo-class';
|
|
9
9
|
import 'consola';
|
|
10
10
|
import 'perfect-debounce';
|
|
11
11
|
import 'picocolors';
|
|
12
|
+
import 'vite-plugin-full-reload';
|
|
12
13
|
import 'fs';
|
|
13
14
|
import 'path';
|
|
14
15
|
import 'module';
|
|
@@ -17,3 +18,4 @@ import 'zlib';
|
|
|
17
18
|
import 'util';
|
|
18
19
|
import 'unconfig';
|
|
19
20
|
import 'magic-string';
|
|
21
|
+
import 'detect-package-manager';
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
const getComponentName = (path) => path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).toLowerCase();
|
|
2
2
|
const kirbyup = Object.freeze({
|
|
3
3
|
import(modules) {
|
|
4
|
-
return Object.entries(modules).reduce(
|
|
5
|
-
accumulator[
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return Object.entries(modules).reduce(
|
|
5
|
+
(accumulator, [path, component]) => {
|
|
6
|
+
accumulator[getComponentName(path)] = component.default;
|
|
7
|
+
return accumulator;
|
|
8
|
+
},
|
|
9
|
+
{}
|
|
10
|
+
);
|
|
8
11
|
}
|
|
9
12
|
});
|
|
10
13
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { existsSync as existsSync$1 } from 'node:fs';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
1
|
+
import { existsSync as existsSync$1, unlinkSync } from 'node:fs';
|
|
2
|
+
import { writeFile, readFile } from 'node:fs/promises';
|
|
3
3
|
import { normalize, relative, resolve as resolve$1, dirname, basename } from 'pathe';
|
|
4
|
-
import { transformWithEsbuild, formatPostcssSourceMap, build as build$1
|
|
4
|
+
import { transformWithEsbuild, formatPostcssSourceMap, createServer, mergeConfig, build as build$1 } from 'vite';
|
|
5
5
|
import fs, { existsSync, statSync } from 'fs';
|
|
6
6
|
import path$2, { win32, posix, isAbsolute, resolve } from 'path';
|
|
7
7
|
import { createRequire } from 'module';
|
|
@@ -12,10 +12,12 @@ import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
|
|
|
12
12
|
import consola from 'consola';
|
|
13
13
|
import { debounce } from 'perfect-debounce';
|
|
14
14
|
import colors from 'picocolors';
|
|
15
|
+
import fullReloadPlugin from 'vite-plugin-full-reload';
|
|
15
16
|
import { gzip } from 'zlib';
|
|
16
17
|
import { promisify } from 'util';
|
|
17
18
|
import { createConfigLoader } from 'unconfig';
|
|
18
19
|
import MagicString from 'magic-string';
|
|
20
|
+
import { detect } from 'detect-package-manager';
|
|
19
21
|
|
|
20
22
|
var utils$3 = {};
|
|
21
23
|
|
|
@@ -3268,7 +3270,7 @@ function vuePlugin(rawOptions = {}) {
|
|
|
3268
3270
|
}
|
|
3269
3271
|
|
|
3270
3272
|
const name = "kirbyup";
|
|
3271
|
-
const version = "
|
|
3273
|
+
const version = "2.0.0-beta.0";
|
|
3272
3274
|
|
|
3273
3275
|
class PrettyError extends Error {
|
|
3274
3276
|
constructor(message) {
|
|
@@ -3301,12 +3303,11 @@ async function printFileInfo(root, outDir, filePath, content, type, maxLength) {
|
|
|
3301
3303
|
const kibs = content.length / 1024;
|
|
3302
3304
|
const compressedSize = await getCompressedSize(content);
|
|
3303
3305
|
const writeColor = type === "chunk" ? colors.cyan : colors.magenta;
|
|
3304
|
-
consola.log(
|
|
3306
|
+
consola.log(
|
|
3307
|
+
colors.white(colors.dim(prettyOutDir)) + writeColor(filePath.padEnd(maxLength + 2)) + colors.dim(`${kibs.toFixed(2)} KiB${compressedSize}`)
|
|
3308
|
+
);
|
|
3305
3309
|
}
|
|
3306
3310
|
|
|
3307
|
-
function defineConfig(config) {
|
|
3308
|
-
return config;
|
|
3309
|
-
}
|
|
3310
3311
|
async function loadConfig(cwd = process.cwd(), configOrPath = cwd, extraConfigSources = []) {
|
|
3311
3312
|
let inlineConfig = {};
|
|
3312
3313
|
if (typeof configOrPath !== "string") {
|
|
@@ -3366,7 +3367,11 @@ function kirbyupAutoImportPlugin() {
|
|
|
3366
3367
|
const { 0: exp, 1: rawPath, index } = match;
|
|
3367
3368
|
if (!s)
|
|
3368
3369
|
s = new MagicString(code);
|
|
3369
|
-
s.overwrite(
|
|
3370
|
+
s.overwrite(
|
|
3371
|
+
index,
|
|
3372
|
+
index + exp.length,
|
|
3373
|
+
`kirbyup.import(import.meta.glob(${rawPath}, { eager: true }))`
|
|
3374
|
+
);
|
|
3370
3375
|
}
|
|
3371
3376
|
if (s) {
|
|
3372
3377
|
return {
|
|
@@ -3380,17 +3385,105 @@ function kirbyupAutoImportPlugin() {
|
|
|
3380
3385
|
};
|
|
3381
3386
|
}
|
|
3382
3387
|
|
|
3388
|
+
const __HMR_CODE__ = `
|
|
3389
|
+
if (typeof __VUE_HMR_RUNTIME__ !== 'undefined' && import.meta.hot) {
|
|
3390
|
+
__VUE_HMR_RUNTIME__.reload = () => import.meta.hot.invalidate();
|
|
3391
|
+
}`.trim();
|
|
3392
|
+
const getViteProxyModule = (entryUrl, pm) => `
|
|
3393
|
+
try {
|
|
3394
|
+
await import("${entryUrl}");
|
|
3395
|
+
} catch (err) {
|
|
3396
|
+
console.error(
|
|
3397
|
+
"[kirbyup] Couldn't connect to the development server. Run \`${pm} run dev\` to start Vite or build the plugin with \`${pm} run build\` so Kirby uses the production version."
|
|
3398
|
+
);
|
|
3399
|
+
throw err;
|
|
3400
|
+
}`.trim();
|
|
3401
|
+
function kirbyupHmrPlugin(options) {
|
|
3402
|
+
let config;
|
|
3403
|
+
let entry;
|
|
3404
|
+
let indexMjs;
|
|
3405
|
+
return {
|
|
3406
|
+
name: "kirbyup:hmr",
|
|
3407
|
+
apply: "serve",
|
|
3408
|
+
configResolved(resolvedConfig) {
|
|
3409
|
+
config = resolvedConfig;
|
|
3410
|
+
entry = resolve$1(config.root, options.entry);
|
|
3411
|
+
indexMjs = resolve$1(config.root, options.outDir || "", "index.dev.mjs");
|
|
3412
|
+
},
|
|
3413
|
+
transform(code, id) {
|
|
3414
|
+
const { query } = parseVueRequest(id);
|
|
3415
|
+
if (query.raw)
|
|
3416
|
+
return;
|
|
3417
|
+
if ((typeof id !== "string" || /\0/.test(id)) && !query.vue)
|
|
3418
|
+
return;
|
|
3419
|
+
if (/\.vue$/.test(id) && !query.vue)
|
|
3420
|
+
return `${code};${__HMR_CODE__}`;
|
|
3421
|
+
},
|
|
3422
|
+
configureServer(server) {
|
|
3423
|
+
if (!server.httpServer)
|
|
3424
|
+
return;
|
|
3425
|
+
server.httpServer.once("listening", async () => {
|
|
3426
|
+
const entryPath = entry.replace(`${config.root}/`, "");
|
|
3427
|
+
const { address, port } = server.httpServer.address();
|
|
3428
|
+
const baseUrl = `http://${address}:${port}${config.base}`;
|
|
3429
|
+
const entryUrl = new URL(entryPath, baseUrl).href;
|
|
3430
|
+
const pm = await detect().catch(() => "npm");
|
|
3431
|
+
await writeFile(indexMjs, getViteProxyModule(entryUrl, pm));
|
|
3432
|
+
});
|
|
3433
|
+
},
|
|
3434
|
+
closeBundle() {
|
|
3435
|
+
if (existsSync$1(indexMjs))
|
|
3436
|
+
unlinkSync(indexMjs);
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3441
|
+
function kirbyupBuildCleanupPlugin(options) {
|
|
3442
|
+
let config;
|
|
3443
|
+
let indexMjs;
|
|
3444
|
+
return {
|
|
3445
|
+
name: "kirbyup:build-cleanup",
|
|
3446
|
+
configResolved(resolvedConfig) {
|
|
3447
|
+
config = resolvedConfig;
|
|
3448
|
+
indexMjs = resolve$1(config.root, options.outDir, "index.dev.mjs");
|
|
3449
|
+
},
|
|
3450
|
+
writeBundle() {
|
|
3451
|
+
if (existsSync$1(indexMjs))
|
|
3452
|
+
unlinkSync(indexMjs);
|
|
3453
|
+
}
|
|
3454
|
+
};
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3383
3457
|
let resolvedKirbyupConfig;
|
|
3384
3458
|
let resolvedPostCssConfig;
|
|
3385
|
-
|
|
3386
|
-
let result;
|
|
3387
|
-
const mode = options.watch ? "development" : "production";
|
|
3388
|
-
const outDir = options.outDir || options.cwd;
|
|
3459
|
+
function getViteConfig(command, options) {
|
|
3389
3460
|
const aliasDir = resolve$1(options.cwd, dirname(options.entry));
|
|
3390
3461
|
const { alias = {}, extendViteConfig = {} } = resolvedKirbyupConfig;
|
|
3391
|
-
const
|
|
3392
|
-
|
|
3462
|
+
const baseConfig = {
|
|
3463
|
+
resolve: {
|
|
3464
|
+
alias: { "~/": `${aliasDir}/`, "@/": `${aliasDir}/`, ...alias }
|
|
3465
|
+
},
|
|
3393
3466
|
plugins: [vuePlugin(), kirbyupAutoImportPlugin()],
|
|
3467
|
+
css: { postcss: resolvedPostCssConfig },
|
|
3468
|
+
envPrefix: ["VITE_", "KIRBYUP_"],
|
|
3469
|
+
logLevel: "warn"
|
|
3470
|
+
};
|
|
3471
|
+
if (command === "serve") {
|
|
3472
|
+
const { port, watch } = options;
|
|
3473
|
+
const serveConfig = mergeConfig(baseConfig, {
|
|
3474
|
+
plugins: [
|
|
3475
|
+
kirbyupHmrPlugin(options),
|
|
3476
|
+
watch && fullReloadPlugin(watch)
|
|
3477
|
+
],
|
|
3478
|
+
build: { rollupOptions: { input: resolve$1(options.cwd, options.entry) } },
|
|
3479
|
+
server: { port, strictPort: true, origin: `http://localhost:${port}` }
|
|
3480
|
+
});
|
|
3481
|
+
return mergeConfig(serveConfig, extendViteConfig);
|
|
3482
|
+
}
|
|
3483
|
+
const mode = options.watch ? "development" : "production";
|
|
3484
|
+
const buildConfig = mergeConfig(baseConfig, {
|
|
3485
|
+
plugins: [kirbyupBuildCleanupPlugin(options)],
|
|
3486
|
+
mode,
|
|
3394
3487
|
build: {
|
|
3395
3488
|
lib: {
|
|
3396
3489
|
entry: resolve$1(options.cwd, options.entry),
|
|
@@ -3399,36 +3492,27 @@ async function generate(options) {
|
|
|
3399
3492
|
fileName: () => "index.js"
|
|
3400
3493
|
},
|
|
3401
3494
|
minify: mode === "production",
|
|
3402
|
-
outDir,
|
|
3495
|
+
outDir: options.outDir,
|
|
3403
3496
|
emptyOutDir: false,
|
|
3404
3497
|
rollupOptions: {
|
|
3405
3498
|
external: ["vue"],
|
|
3406
3499
|
output: {
|
|
3407
3500
|
assetFileNames: "index.[ext]",
|
|
3408
|
-
globals: {
|
|
3409
|
-
vue: "Vue"
|
|
3410
|
-
}
|
|
3501
|
+
globals: { vue: "Vue" }
|
|
3411
3502
|
}
|
|
3412
3503
|
}
|
|
3413
|
-
}
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
},
|
|
3421
|
-
css: {
|
|
3422
|
-
postcss: resolvedPostCssConfig
|
|
3423
|
-
},
|
|
3424
|
-
envPrefix: ["VITE_", "KIRBYUP_"],
|
|
3425
|
-
logLevel: "warn"
|
|
3426
|
-
};
|
|
3504
|
+
}
|
|
3505
|
+
});
|
|
3506
|
+
return mergeConfig(buildConfig, extendViteConfig);
|
|
3507
|
+
}
|
|
3508
|
+
async function generate(options) {
|
|
3509
|
+
const config = getViteConfig("build", options);
|
|
3510
|
+
let result;
|
|
3427
3511
|
try {
|
|
3428
|
-
result = await build$1(
|
|
3512
|
+
result = await build$1(config);
|
|
3429
3513
|
} catch (error) {
|
|
3430
3514
|
consola.error("Build failed");
|
|
3431
|
-
if (mode === "production")
|
|
3515
|
+
if (config.mode === "production")
|
|
3432
3516
|
throw error;
|
|
3433
3517
|
}
|
|
3434
3518
|
if (result && !options.watch) {
|
|
@@ -3439,23 +3523,25 @@ async function generate(options) {
|
|
|
3439
3523
|
if (l > longest)
|
|
3440
3524
|
longest = l;
|
|
3441
3525
|
}
|
|
3442
|
-
for (const {
|
|
3443
|
-
|
|
3526
|
+
for (const {
|
|
3527
|
+
fileName,
|
|
3528
|
+
type,
|
|
3529
|
+
code
|
|
3530
|
+
} of output) {
|
|
3531
|
+
await printFileInfo(
|
|
3532
|
+
options.cwd,
|
|
3533
|
+
options.outDir,
|
|
3534
|
+
fileName,
|
|
3535
|
+
code ?? await readFile(resolve$1(options.outDir, fileName), "utf8"),
|
|
3536
|
+
type,
|
|
3537
|
+
longest
|
|
3538
|
+
);
|
|
3444
3539
|
}
|
|
3445
3540
|
}
|
|
3446
3541
|
return result;
|
|
3447
3542
|
}
|
|
3448
|
-
async function
|
|
3449
|
-
options
|
|
3450
|
-
if (!options.entry) {
|
|
3451
|
-
throw new PrettyError(`No input file, try ${colors.cyan(`${name} <path/to/file.js>`)}`);
|
|
3452
|
-
}
|
|
3453
|
-
if (!existsSync$1(resolve$1(options.cwd, options.entry)))
|
|
3454
|
-
throw new PrettyError(`Cannot find "${options.entry}"`);
|
|
3455
|
-
return options;
|
|
3456
|
-
}
|
|
3457
|
-
async function build(_options) {
|
|
3458
|
-
const options = await resolveOptions(_options);
|
|
3543
|
+
async function build(options) {
|
|
3544
|
+
ensureEntry(options);
|
|
3459
3545
|
const { cwd } = options;
|
|
3460
3546
|
const { config, sources: configSources } = await loadConfig(cwd);
|
|
3461
3547
|
resolvedKirbyupConfig = config;
|
|
@@ -3485,8 +3571,12 @@ async function build(_options) {
|
|
|
3485
3571
|
"**/{.git,node_modules}/**",
|
|
3486
3572
|
"index.{css,js}"
|
|
3487
3573
|
];
|
|
3488
|
-
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
|
|
3489
|
-
|
|
3574
|
+
const watchPaths = typeof options.watch === "boolean" ? dirname(options.entry) : Array.isArray(options.watch) ? options.watch.filter(
|
|
3575
|
+
(path) => typeof path === "string"
|
|
3576
|
+
) : options.watch;
|
|
3577
|
+
consola.info(
|
|
3578
|
+
`Watching for changes in ${toArray(watchPaths).map((i) => colors.cyan(i)).join(", ")}`
|
|
3579
|
+
);
|
|
3490
3580
|
const watcher = watch(watchPaths, {
|
|
3491
3581
|
ignoreInitial: true,
|
|
3492
3582
|
ignorePermissionErrors: true,
|
|
@@ -3498,7 +3588,9 @@ async function build(_options) {
|
|
|
3498
3588
|
watcher.on("all", async (type, file) => {
|
|
3499
3589
|
if (configSources.includes(file)) {
|
|
3500
3590
|
resolvedKirbyupConfig = (await loadConfig()).config;
|
|
3501
|
-
consola.info(
|
|
3591
|
+
consola.info(
|
|
3592
|
+
`${colors.cyan(basename(file))} changed, setting new config`
|
|
3593
|
+
);
|
|
3502
3594
|
} else {
|
|
3503
3595
|
consola.log(`${colors.green(type)} ${colors.white(colors.dim(file))}`);
|
|
3504
3596
|
}
|
|
@@ -3509,5 +3601,32 @@ async function build(_options) {
|
|
|
3509
3601
|
consola.success("Build successful");
|
|
3510
3602
|
startWatcher();
|
|
3511
3603
|
}
|
|
3604
|
+
async function serve(options) {
|
|
3605
|
+
ensureEntry(options);
|
|
3606
|
+
const { cwd } = options;
|
|
3607
|
+
const { config } = await loadConfig(cwd);
|
|
3608
|
+
resolvedKirbyupConfig = config;
|
|
3609
|
+
try {
|
|
3610
|
+
resolvedPostCssConfig = await postcssrc({});
|
|
3611
|
+
} catch (err) {
|
|
3612
|
+
if (!/No PostCSS Config found/.test(err.message))
|
|
3613
|
+
throw err;
|
|
3614
|
+
resolvedPostCssConfig = {
|
|
3615
|
+
plugins: [postcssLogical(), postcssDirPseudoClass()]
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
{
|
|
3619
|
+
consola.log(colors.green(`${name} v${version}`));
|
|
3620
|
+
consola.info("Starting development server...");
|
|
3621
|
+
}
|
|
3622
|
+
const server = await createServer(getViteConfig("serve", options));
|
|
3623
|
+
await server.listen();
|
|
3624
|
+
consola.success(`Server is listening on :${server.config.server.port}`);
|
|
3625
|
+
return server;
|
|
3626
|
+
}
|
|
3627
|
+
function ensureEntry(options) {
|
|
3628
|
+
if (!existsSync$1(resolve$1(options.cwd, options.entry)))
|
|
3629
|
+
throw new PrettyError(`Cannot find "${options.entry}"`);
|
|
3630
|
+
}
|
|
3512
3631
|
|
|
3513
|
-
export { build as b,
|
|
3632
|
+
export { build as b, handleError as h, name as n, serve as s, version as v };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AliasOptions, InlineConfig } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface BaseOptions {
|
|
4
|
+
cwd: string;
|
|
5
|
+
entry: string;
|
|
6
|
+
}
|
|
7
|
+
interface ServeOptions extends BaseOptions {
|
|
8
|
+
watch: false | string | string[];
|
|
9
|
+
port: number;
|
|
10
|
+
outDir?: string;
|
|
11
|
+
}
|
|
12
|
+
interface BuildOptions extends BaseOptions {
|
|
13
|
+
outDir: string;
|
|
14
|
+
watch: boolean | string | string[];
|
|
15
|
+
}
|
|
16
|
+
interface UserConfig {
|
|
17
|
+
/**
|
|
18
|
+
* Load from config files
|
|
19
|
+
* Set to `false` to disable
|
|
20
|
+
*/
|
|
21
|
+
configFile?: string | false;
|
|
22
|
+
/**
|
|
23
|
+
* Specifies an `Object`, or an `Array` of `Object`,
|
|
24
|
+
* which defines aliases used to replace values in `import` statements.
|
|
25
|
+
* With either format, the order of the entries is important,
|
|
26
|
+
* in that the first defined rules are applied first.
|
|
27
|
+
*/
|
|
28
|
+
alias?: AliasOptions;
|
|
29
|
+
/**
|
|
30
|
+
* Extends Vite's configuration. Will be merged with kirbyup's
|
|
31
|
+
* default configuration. Be careful what to extend.
|
|
32
|
+
*/
|
|
33
|
+
extendViteConfig?: InlineConfig;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { BuildOptions as B, ServeOptions as S, UserConfig as U };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kirbyup",
|
|
3
|
-
"version": "
|
|
4
|
-
"packageManager": "pnpm@7.
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"packageManager": "pnpm@7.9.0",
|
|
5
5
|
"description": "Zero-config bundler for Kirby Panel plugins",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Johann Schopplich",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"import": "./dist/index.mjs"
|
|
32
32
|
},
|
|
33
|
+
"./config": {
|
|
34
|
+
"types": "./dist/config.d.ts",
|
|
35
|
+
"import": "./dist/config.mjs"
|
|
36
|
+
},
|
|
33
37
|
"./plugin": {
|
|
34
38
|
"types": "./dist/plugin.d.ts",
|
|
35
39
|
"import": "./dist/plugin.mjs"
|
|
@@ -37,6 +41,16 @@
|
|
|
37
41
|
},
|
|
38
42
|
"module": "./dist/index.mjs",
|
|
39
43
|
"types": "./dist/index.d.ts",
|
|
44
|
+
"typesVersions": {
|
|
45
|
+
"*": {
|
|
46
|
+
"config": [
|
|
47
|
+
"./dist/config.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"plugin": [
|
|
50
|
+
"./dist/plugin.d.ts"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
40
54
|
"bin": "./cli.mjs",
|
|
41
55
|
"files": [
|
|
42
56
|
"bin",
|
|
@@ -53,41 +67,47 @@
|
|
|
53
67
|
"release": "bumpp --commit --push --tag",
|
|
54
68
|
"test": "vitest",
|
|
55
69
|
"typecheck": "tsc --noEmit",
|
|
56
|
-
"prepare": "
|
|
70
|
+
"prepare": "simple-git-hooks"
|
|
57
71
|
},
|
|
58
72
|
"dependencies": {
|
|
59
|
-
"@vue/compiler-sfc": "^2.7.
|
|
73
|
+
"@vue/compiler-sfc": "^2.7.8",
|
|
60
74
|
"cac": "^6.7.12",
|
|
61
75
|
"chokidar": "^3.5.3",
|
|
62
76
|
"consola": "^2.15.3",
|
|
77
|
+
"detect-package-manager": "^2.0.1",
|
|
63
78
|
"magic-string": "^0.26.2",
|
|
64
|
-
"pathe": "^0.3.
|
|
79
|
+
"pathe": "^0.3.5",
|
|
65
80
|
"perfect-debounce": "^0.1.3",
|
|
66
81
|
"picocolors": "^1.0.0",
|
|
67
|
-
"postcss": "^8.4.
|
|
82
|
+
"postcss": "^8.4.16",
|
|
68
83
|
"postcss-dir-pseudo-class": "^6.0.5",
|
|
69
84
|
"postcss-load-config": "^4.0.1",
|
|
70
85
|
"postcss-logical": "^5.0.4",
|
|
71
|
-
"sass": "^1.
|
|
86
|
+
"sass": "^1.54.4",
|
|
72
87
|
"unconfig": "^0.3.5",
|
|
73
|
-
"vite": "^3.0.
|
|
74
|
-
"
|
|
88
|
+
"vite": "^3.0.8",
|
|
89
|
+
"vite-plugin-full-reload": "^1.0.4",
|
|
90
|
+
"vue": "^2.7.8"
|
|
75
91
|
},
|
|
76
92
|
"devDependencies": {
|
|
77
|
-
"@antfu/eslint-config": "^0.
|
|
93
|
+
"@antfu/eslint-config": "^0.26.1",
|
|
78
94
|
"@types/fs-extra": "^9.0.13",
|
|
79
|
-
"@types/node": "^18.
|
|
95
|
+
"@types/node": "^18.7.6",
|
|
80
96
|
"@types/prompts": "^2.4.0",
|
|
81
97
|
"@vitejs/plugin-vue2": "^1.1.2",
|
|
82
98
|
"bumpp": "^8.2.1",
|
|
83
|
-
"eslint": "^8.
|
|
99
|
+
"eslint": "^8.22.0",
|
|
84
100
|
"fast-glob": "^3.2.11",
|
|
85
101
|
"fs-extra": "^10.1.0",
|
|
86
|
-
"patch-package": "^6.4.7",
|
|
87
102
|
"simple-git-hooks": "^2.8.0",
|
|
88
103
|
"typescript": "^4.7.4",
|
|
89
|
-
"unbuild": "^0.
|
|
90
|
-
"vitest": "^0.
|
|
104
|
+
"unbuild": "^0.8.8",
|
|
105
|
+
"vitest": "^0.22.1"
|
|
106
|
+
},
|
|
107
|
+
"pnpm": {
|
|
108
|
+
"patchedDependencies": {
|
|
109
|
+
"@vitejs/plugin-vue2@1.1.2": "patches/@vitejs__plugin-vue2@1.1.2.patch"
|
|
110
|
+
}
|
|
91
111
|
},
|
|
92
112
|
"simple-git-hooks": {
|
|
93
113
|
"commit-msg": "node scripts/verifyCommit.mjs $1"
|