liuweiGL / vite-plugin-mkcert

Provide certificates for vite's https dev service.
https://www.npmjs.com/package/vite-plugin-mkcert
MIT License
544 stars 37 forks source link

Abillty to specify download directory #20

Closed delebash closed 2 years ago

delebash commented 2 years ago

Clear and concise description of the problem

Be able to specify cert download location instead of default PLUGIN_DIR This will allow me to easily use the certs from a central location of my choosing

liuweiGL commented 2 years ago

Just use import { PLUGIN_DATA_DIR } from 'vite-plugin-mkcert/dist/lib/constant'

p6l-richard commented 1 year ago

I'm trying to use the constant to set up live-server https configuration but am unable to do so. Is there a way to use this constant for config files in JS?

> outlook@0.0.0 dev /Users/XXXX/frontend/apps/outlook
> live-server ./dist --port 8082 --no-browser --https=./live-server.config.js

node:internal/modules/cjs/loader:499
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/lib/constant' is not defined by "exports" in /Users/XXXX/frontend/apps/outlook/node_modules/vite-plugin-mkcert/package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:439:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:718:3)
    at resolveExports (node:internal/modules/cjs/loader:493:36)
    at Module._findPath (node:internal/modules/cjs/loader:533:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
    at Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/XXXX/frontend/apps/outlook/live-server.config.js:2:14) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
// package.json
//...
  "scripts": {
    "dev": "live-server ./dist --port 8082 --no-browser --https=./live-server.config.js",
  }
// live-server.config.js
var fs = require('fs')
var mkcert = require('vite-plugin-mkcert/dist/lib/constant')

/**
 * @type {import('tls').SecureContextOptions}
 */

const config = {
  cert: fs.readFileSync(mkcert.PLUGIN_DATA_DIR + '/certs/dev.pem'),
  key: fs.readFileSync(mkcert.PLUGIN_DATA_DIR + '/certs/dev.key'),
}

module.exports = config