LinbuduLab / esbuild-plugins

ESBuild plugins by @LinbuduLab
MIT License
113 stars 18 forks source link

Ports from vite.config file should be respected #60

Closed alykamb closed 2 years ago

alykamb commented 2 years ago

Hi, thanks for the package, it worked greatly so far. I have only one issue with currently enforced port 3000.

Currently the execution script forces a static port from the project.json file. I have a special case where the port is given dynamically from the environment. Why force the port in the project.json file, if it can be set statically as well directly on vite.config.ts file?

The given snippet works fine, and respects the ports from vite.config.ts file, also keeping the default port 3000 from vite if no port is given (and trying different ones if the 3000 is taken):

const { root, configFile } = schema;

  const serverFactory = await createServer({
    root,
    configFile, //remove server config, and let vite.config.ts define it
  });

  consola.info(chalk.cyan('Nx-Vite [Start] Starting \n'));

  const devServer = await serverFactory.listen(); //remove port here

  consola.success(
    `Vite server ready at ${chalk.green(
      `${https ? 'https:' : 'http:'}//localhost:${devServer.config.server.port}` //display the port actually used by the dev server
    )}`
  );

If you agree, I can make a PR

linbudu599 commented 2 years ago

This is indeed a mistake and thanks for your great work!