Skip to content

Commit

Permalink
feat: environment specific certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Sep 27, 2021
1 parent 6943247 commit ea5bab2
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 113 deletions.
14 changes: 13 additions & 1 deletion docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,19 @@ If you need to pass a configuration object, use the latter.

### SSL certificates

If your local environment is using the `https` protocol, you'll need to configure Vite's development server to use your SSL certificates. You can do this using `withCertificates`. The parameters are the paths to the `.key` and the `.crt` files, respectively.
If your local environment is using the `https` protocol, you'll need to configure Vite's development server to use your SSL certificates. You can do this using `withCertificates`. The parameters are the paths to the `.key` and the `.crt` files, respectively.

#### Environment-specific certificates

If you share your project between different environments, you can use pass a callback to `withCertificates` and return a tuple which contains the paths to the `.key` and the `.crt`:

```ts
export default defineConfig()
.withCertificates((env) => ([
env.VITE_DEV_KEY,
env.VITE_DEV_CERT,
]))
```

#### Laravel Valet

Expand Down
77 changes: 41 additions & 36 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
{
"name": "laravel-vite",
"version": "0.0.16",
"author": "Enzo Innocenzi",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/innocenzi/laravel-vite"
},
"homepage": "https://github.com/innocenzi/laravel-vite#readme",
"bugs": "https://github.com/innocenzi/laravel-vite/issues",
"scripts": {
"prepare": "npm run build",
"dev": "npm run build -- --watch",
"build": "tsup src/index.ts --dts --format cjs,esm"
},
"devDependencies": {
"@innocenzi/eslint-config": "^0.1.10",
"@types/debug": "^4.1.7",
"@types/node": "^16.3.1",
"eslint": "^7.30.0",
"tsup": "^4.12.5",
"typescript": "^4.3.5",
"vite": "^2.4.1"
},
"dependencies": {
"chalk": "^4.1.1",
"deepmerge": "^4.2.2",
"dotenv": "^10.0.0",
"execa": "^5.1.1"
}
"name": "laravel-vite",
"version": "0.0.17",
"author": "Enzo Innocenzi",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/innocenzi/laravel-vite"
},
"homepage": "https://github.com/innocenzi/laravel-vite#readme",
"bugs": "https://github.com/innocenzi/laravel-vite/issues",
"scripts": {
"prepare": "npm run build",
"dev": "npm run build -- --watch",
"build": "tsup src/index.ts --dts --format cjs,esm"
},
"devDependencies": {
"@innocenzi/eslint-config": "^0.3.1",
"@types/debug": "^4.1.7",
"@types/deepmerge": "^2.2.0",
"@types/execa": "^2.0.0",
"@types/node": "^16.10.1",
"eslint": "^7.32.0",
"rollup": "^2.57.0",
"tsup": "^5.2.1",
"typescript": "^4.4.3",
"vite": "^2.5.10"
},
"dependencies": {
"chalk": "^4.1.2",
"debug": "^4.3.2",
"deepmerge": "^4.2.2",
"dotenv": "^10.0.0",
"execa": "^5.1.1",
"postcss": "^8.3.8"
}
}
10 changes: 8 additions & 2 deletions npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,18 @@ export class ViteConfiguration {
/**
* Configures the development server to use the certificates at the given paths.
*/
public withCertificates(key: string, cert: string): this {
public withCertificates(callback: (env: typeof process.env) => [string, string]): this
public withCertificates(key: string, cert: string): this
public withCertificates(callbackOrKey: string | ((env: typeof process.env) => [string, string]), cert?: string): this {
if (typeof callbackOrKey === 'function') {
[callbackOrKey, cert] = callbackOrKey(process.env)
}

return this.merge({
server: {
https: {
maxVersion: 'TLSv1.2',
key,
key: callbackOrKey as string,
cert,
},
},
Expand Down
Loading

0 comments on commit ea5bab2

Please # to comment.