@kopflos-cms/vite 0.3.3 → 0.3.5
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/CHANGELOG.md +13 -0
- package/index.d.ts +4 -2
- package/index.js +10 -6
- package/lib/config.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @kopflos-cms/vite
|
|
2
2
|
|
|
3
|
+
## 0.3.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c9ff747: `log` field is now protected so that impementing plugins can log more easily
|
|
8
|
+
|
|
9
|
+
## 0.3.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5c7f745: update glob to v13
|
|
14
|
+
- 78ac295: Serve dev server using `beforeMiddleware` but build output using `afterMiddleware` to avoid raw HTML responses
|
|
15
|
+
|
|
3
16
|
## 0.3.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Kopflos, KopflosEnvironment, KopflosPlugin } from '@kopflos-cms/core';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import type { InlineConfig, ViteDevServer } from 'vite';
|
|
4
|
+
import { createLogger } from '@kopflos-cms/logger';
|
|
4
5
|
export { defineConfig } from 'vite';
|
|
5
6
|
export interface BuildConfiguration {
|
|
6
7
|
root: string;
|
|
@@ -16,7 +17,7 @@ declare module '@kopflos-cms/core' {
|
|
|
16
17
|
export declare abstract class VitePlugin implements KopflosPlugin {
|
|
17
18
|
readonly name: string;
|
|
18
19
|
protected readonly buildConfigurations: Array<BuildConfiguration>;
|
|
19
|
-
|
|
20
|
+
protected readonly log: ReturnType<typeof createLogger>;
|
|
20
21
|
private _viteDevServer;
|
|
21
22
|
protected constructor(name: string, buildConfigurations: Array<BuildConfiguration>);
|
|
22
23
|
protected getDefaultPlugin(plugins: readonly KopflosPlugin[]): DefaultPlugin;
|
|
@@ -24,6 +25,7 @@ export declare abstract class VitePlugin implements KopflosPlugin {
|
|
|
24
25
|
private createConfig;
|
|
25
26
|
private resolveOutDir;
|
|
26
27
|
beforeMiddleware(host: express.Router, { env, plugins }: Kopflos): Promise<void>;
|
|
28
|
+
afterMiddleware(host: express.Router, { env }: Kopflos): Promise<void>;
|
|
27
29
|
build(env: KopflosEnvironment, plugins: readonly KopflosPlugin[]): Promise<void>;
|
|
28
30
|
}
|
|
29
31
|
interface DefaultPluginOptions {
|
|
@@ -35,7 +37,7 @@ export default class DefaultPlugin extends VitePlugin {
|
|
|
35
37
|
readonly config: InlineConfig | undefined;
|
|
36
38
|
readonly configPath: string | undefined;
|
|
37
39
|
readonly buildConfiguration?: BuildConfiguration;
|
|
38
|
-
constructor({ build, config, configPath }
|
|
40
|
+
constructor({ build, config, configPath }?: DefaultPluginOptions);
|
|
39
41
|
protected getDefaultPlugin(): this;
|
|
40
42
|
getDefaultViteDevServer(env: KopflosEnvironment): Promise<ViteDevServer>;
|
|
41
43
|
}
|
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export class VitePlugin {
|
|
|
9
9
|
this.name = name;
|
|
10
10
|
this.buildConfigurations = buildConfigurations;
|
|
11
11
|
this._viteDevServer = new WeakMap();
|
|
12
|
-
this.log = createLogger(this.name.replace(/^@kopflos-cms\//, ''));
|
|
12
|
+
this.log = createLogger(this.name.replace(/^@kopflos-(cms|labs)\//, ''));
|
|
13
13
|
}
|
|
14
14
|
getDefaultPlugin(plugins) {
|
|
15
15
|
const defaultPlugin = plugins.find(plugin => plugin instanceof DefaultPlugin);
|
|
@@ -41,14 +41,18 @@ export class VitePlugin {
|
|
|
41
41
|
return resolve(env.kopflos.basePath, env.kopflos.buildDir, options.outDir || '');
|
|
42
42
|
}
|
|
43
43
|
async beforeMiddleware(host, { env, plugins }) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
if (env.kopflos.config.mode === 'development') {
|
|
45
|
+
const vitePlugin = this.getDefaultPlugin(plugins);
|
|
46
|
+
for (const options of this.buildConfigurations) {
|
|
47
47
|
this.log.info('Development UI mode. Creating Vite server...');
|
|
48
48
|
const viteDevServer = await this.getViteDevServer(env, vitePlugin, options);
|
|
49
49
|
host.use(viteDevServer.middlewares);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async afterMiddleware(host, { env }) {
|
|
54
|
+
if (env.kopflos.config.mode === 'production') {
|
|
55
|
+
for (const options of this.buildConfigurations) {
|
|
52
56
|
const buildDir = this.resolveOutDir(env, options);
|
|
53
57
|
this.log.info('Serving from build directory');
|
|
54
58
|
this.log.debug('Build directory:', buildDir);
|
|
@@ -70,7 +74,7 @@ export class VitePlugin {
|
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
export default class DefaultPlugin extends VitePlugin {
|
|
73
|
-
constructor({ build = [], config, configPath }) {
|
|
77
|
+
constructor({ build = [], config, configPath } = {}) {
|
|
74
78
|
if (!Array.isArray(build)) {
|
|
75
79
|
super('@kopflos-cms/vite', [build]);
|
|
76
80
|
this.buildConfiguration = build;
|
package/lib/config.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function prepareConfig({ appRoot, root, entrypoints, outDir, config
|
|
|
22
22
|
if (config.startsWith('.')) {
|
|
23
23
|
config = resolve(appRoot, config);
|
|
24
24
|
}
|
|
25
|
-
userConfig = (await import(config)).default;
|
|
25
|
+
userConfig = (await import(/* @vite-ignore */ config)).default;
|
|
26
26
|
}
|
|
27
27
|
return [defaultConfig, inputConfig, userConfig, buildConfig]
|
|
28
28
|
.reduce((merged, next) => mergeConfig(merged, next), {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kopflos-cms/vite",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Zazuko GmbH",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@kopflos-cms/logger": "^0.1.0",
|
|
31
31
|
"express": "^5.2.0",
|
|
32
|
-
"glob": "^
|
|
32
|
+
"glob": "^13.0.5",
|
|
33
33
|
"onetime": "^7.0.0",
|
|
34
34
|
"vite": "^6.4.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@kopflos-cms/core": "^0.7.
|
|
37
|
+
"@kopflos-cms/core": "^0.7.1",
|
|
38
38
|
"@zazuko/env-node": "^3.0.0",
|
|
39
39
|
"@types/glob": "^8.1.0",
|
|
40
40
|
"chai": "^5.1.1"
|