Skip to content

Commit 6776360

Browse files
authored
fix: write envConfig template to outDir from config (#20)
1 parent 196893e commit 6776360

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/envConfig.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import type { Plugin } from 'vite';
3+
import type { Plugin, ResolvedConfig } from 'vite';
44

55
export function createEnvConfigContent(variables: string[], template: boolean): string {
66
let templateContent = '';
@@ -26,12 +26,12 @@ export interface EnvConfigOptions {
2626
}
2727

2828
export function envConfig(userOptions: Partial<EnvConfigOptions> = {}): Plugin {
29-
let root: string;
29+
let config: ResolvedConfig;
3030
return {
3131
name: 'vite-plugin-env-config',
3232

33-
configResolved(config) {
34-
root = config.root;
33+
configResolved(resolvedConfig) {
34+
config = resolvedConfig;
3535
},
3636

3737
configureServer(server) {
@@ -55,7 +55,7 @@ export function envConfig(userOptions: Partial<EnvConfigOptions> = {}): Plugin {
5555
closeBundle() {
5656
const templateContent = createEnvConfigContent(userOptions.variables || [], true);
5757

58-
const TEMPLATE_PATH = path.join(root, 'dist', 'env-config.template.js');
58+
const TEMPLATE_PATH = path.join(config.root, config.build.outDir, 'env-config.template.js');
5959
fs.mkdirSync(path.dirname(TEMPLATE_PATH), { recursive: true });
6060
fs.writeFileSync(TEMPLATE_PATH, templateContent, 'utf8');
6161
},

0 commit comments

Comments
 (0)