Skip to content

Commit

Permalink
build: Added config for STRICT_PORT (#263)
Browse files Browse the repository at this point in the history
Added support for optional `STRICT_PORT` env.

**Testing**
- Create a `.env.development.local` file in the repo root and set
`STRICT_PORT=true`
- In another checkout of the plugins repo, run `npm start` (or you could
run something else on port 4100)`
- Run `npm start` in repo with the new env file. It should fail due to
port already in use

resolves #262
  • Loading branch information
bmingles authored Feb 7, 2024
1 parent b39ff7e commit 51ef0e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
.vscode/
tsconfig.tsbuildinfo
.env.*local

# Ignore user IntelliJ settings
.idea/
Expand Down
8 changes: 6 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { defineConfig, loadEnv } from 'vite';
const DEFAULT_PORT = 4100;

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const port = Number(env.PORT || process.env.PORT || DEFAULT_PORT);
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '');

const port = Number(env.PORT || DEFAULT_PORT);

// This config doesn't build anything, it just serves the files from the
// plugins directory
return {
publicDir: 'plugins',
server: {
port,
strictPort: true,
},
};
});

0 comments on commit 51ef0e2

Please sign in to comment.