@kopflos-cms/vite 0.1.1 → 0.1.2
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 +7 -0
- package/index.d.ts +4 -2
- package/index.js +13 -10
- package/lib/config.d.ts +1 -1
- package/lib/config.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { KopflosPluginConstructor } from '@kopflos-cms/core';
|
|
2
|
+
import type { InlineConfig } from 'vite';
|
|
2
3
|
export { defineConfig } from 'vite';
|
|
3
4
|
export interface Options {
|
|
4
5
|
configPath?: string;
|
|
6
|
+
config?: InlineConfig;
|
|
5
7
|
root?: string;
|
|
6
8
|
outDir?: string;
|
|
7
9
|
entrypoints?: string[];
|
|
@@ -11,4 +13,4 @@ declare module '@kopflos-cms/core' {
|
|
|
11
13
|
'@kopflos-cms/vite'?: Options;
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
|
-
export default function ({ outDir, ...options }: Options):
|
|
16
|
+
export default function ({ outDir, ...options }: Options): KopflosPluginConstructor;
|
package/index.js
CHANGED
|
@@ -8,16 +8,19 @@ export { defineConfig } from 'vite';
|
|
|
8
8
|
export default function ({ outDir = 'dist', ...options }) {
|
|
9
9
|
const rootDir = resolve(process.cwd(), options.root || '');
|
|
10
10
|
const buildDir = resolve(process.cwd(), outDir);
|
|
11
|
-
return {
|
|
12
|
-
|
|
11
|
+
return class {
|
|
12
|
+
constructor(instance) {
|
|
13
|
+
this.env = instance.env;
|
|
14
|
+
}
|
|
15
|
+
onStart() {
|
|
13
16
|
const viteVars = {
|
|
14
|
-
basePath: env.kopflos.config.mode === 'development' ? rootDir : buildDir,
|
|
17
|
+
basePath: this.env.kopflos.config.mode === 'development' ? rootDir : buildDir,
|
|
15
18
|
};
|
|
16
19
|
log.info('Variables', viteVars);
|
|
17
|
-
env.kopflos.variables.VITE = Object.freeze(viteVars);
|
|
18
|
-
}
|
|
19
|
-
async beforeMiddleware(host
|
|
20
|
-
if (env.kopflos.config.mode === 'development') {
|
|
20
|
+
this.env.kopflos.variables.VITE = Object.freeze(viteVars);
|
|
21
|
+
}
|
|
22
|
+
async beforeMiddleware(host) {
|
|
23
|
+
if (this.env.kopflos.config.mode === 'development') {
|
|
21
24
|
log.info('Development UI mode. Creating Vite server...');
|
|
22
25
|
const viteServer = await createViteServer(options);
|
|
23
26
|
host.use(viteServer.middlewares);
|
|
@@ -27,10 +30,10 @@ export default function ({ outDir = 'dist', ...options }) {
|
|
|
27
30
|
log.debug('Build directory:', buildDir);
|
|
28
31
|
host.use(express.static(buildDir));
|
|
29
32
|
}
|
|
30
|
-
}
|
|
31
|
-
async build() {
|
|
33
|
+
}
|
|
34
|
+
static async build() {
|
|
32
35
|
log.info('Building UI...');
|
|
33
36
|
await build(await prepareConfig({ outDir, ...options }));
|
|
34
|
-
}
|
|
37
|
+
}
|
|
35
38
|
};
|
|
36
39
|
}
|
package/lib/config.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Options } from '../index.js';
|
|
2
|
-
export declare function prepareConfig({ root, configPath, entrypoints, outDir }: Omit<Options, 'mode'>): Promise<Record<string, any>>;
|
|
2
|
+
export declare function prepareConfig({ root, configPath, entrypoints, outDir, config }: Omit<Options, 'mode'>): Promise<Record<string, any>>;
|
package/lib/config.js
CHANGED
|
@@ -2,7 +2,7 @@ import { resolve } from 'node:path';
|
|
|
2
2
|
import { glob } from 'glob';
|
|
3
3
|
import { mergeConfig } from 'vite';
|
|
4
4
|
import defaultConfig from '../vite.config.js';
|
|
5
|
-
export async function prepareConfig({ root, configPath, entrypoints, outDir }) {
|
|
5
|
+
export async function prepareConfig({ root, configPath, entrypoints, outDir, config = {} }) {
|
|
6
6
|
const inputConfig = {
|
|
7
7
|
root,
|
|
8
8
|
build: {
|
|
@@ -21,5 +21,5 @@ export async function prepareConfig({ root, configPath, entrypoints, outDir }) {
|
|
|
21
21
|
const userConfig = await import(configPath);
|
|
22
22
|
return mergeConfig(mergeConfig(defaultConfig, inputConfig), userConfig.default);
|
|
23
23
|
}
|
|
24
|
-
return mergeConfig(defaultConfig, inputConfig);
|
|
24
|
+
return mergeConfig(config, mergeConfig(defaultConfig, inputConfig));
|
|
25
25
|
}
|