Skip to content

Commit

Permalink
set config in common file so that dev is consistently same port
Browse files Browse the repository at this point in the history
everything is set in ./config.js now
  • Loading branch information
DougAnderson444 committed Apr 17, 2024
1 parent 457564a commit a2385dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const devConfig = {
host: 'localhost',
port: 4175,
devBase: 'http://localhost:4175'
};
7 changes: 4 additions & 3 deletions inner-app/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import cheerio from 'cheerio';
import fetch from 'node-fetch';
import fs from 'fs';
import path from 'path';
import { devConfig } from '../config.js';

const devBase = 'http://localhost:4175';
const devBase = devConfig.devBase;
let base;
const env = loadEnv('', process.cwd(), '');

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
if (command == 'serve') {
base = env.DEV_BASE || devBase;
base = devBase;
} else {
base = env.VITE_BASE || env.DEV_BASE || devBase;
base = env.VITE_BASE || devBase;
}

return {
Expand Down
15 changes: 10 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { loadEnv } from 'vite';
import fs from 'fs';
import { encode } from '@stablelib/base64';

const devBase = 'http://localhost:4175';
import { devConfig } from './config.js';
const strictPort = true;

let index = fs.readFileSync('./inner-app/dist/index.html', 'utf-8');
const template = fs.readFileSync('./inner-app/template.js', 'utf-8');
Expand Down Expand Up @@ -42,9 +43,9 @@ export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '');

if (command == 'serve') {
base = devBase;
base = devConfig.devBase;
} else {
base = env.VITE_BASE || devBase;
base = env.VITE_BASE || devConfig.devBase;
}

// add the base to the urls in static/innerApp.js tags
Expand All @@ -70,10 +71,14 @@ export default defineConfig(({ command, mode }) => {
include: ['src/**/*.{test,spec}.{js,ts}']
},
server: {
origin: base,
origin: `http://${devConfig.host}:${devConfig.port}`,
host: devConfig.host,
port: devConfig.port,
strictPort,
fs: {
strict: false
}
}
},
preview: { port: devConfig.port }
};
});

0 comments on commit a2385dd

Please sign in to comment.