Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to remove build folder when in development mode #6055

Closed
4 tasks done
hdodov opened this issue Dec 10, 2021 · 3 comments
Closed
4 tasks done

Option to remove build folder when in development mode #6055

hdodov opened this issue Dec 10, 2021 · 3 comments

Comments

@hdodov
Copy link

hdodov commented Dec 10, 2021

Clear and concise description of the problem

I use Vite with PHP and I need some mechanism to check whether there's a dev server currently running. I can ping http://localhost:3000 with curl from within PHP, but I believe that's inefficient.

I think it'll be better to check for the existence of dist/manifest.json, since it has to be used anyways. If it exists, then just load the production files listed inside. Otherwise, consider that Vite is running in development mode and request the assets from http://localhost:3000.

Currently, that's not possible because the dist folder is removed only when you re-run the build command. If you run Vite in development mode, that folder remains and this manifest.json check can't work.

Suggested solution

Have a setting in vite.config.js that removes the dist folder always, not just on build. Something like build.clean with possible values:

Alternative

A command line option like --clear-dev could also do the job.

Additional context

No response

Validations

@jmartsch
Copy link

Hello @hdodov. You can use https://github.com/andrefelipe/vite-php-setup. I modified the isDev function so that it checks for a manifest file.

$isDevelopment = count(getManifest()) === 0;
function getManifest(): array
{

  if (!is_file(__DIR__ . '/assets/js/manifest.json')) return array();

  $content = file_get_contents(__DIR__ . '/assets/js/manifest.json');
  return json_decode($content, true);
}

However, the manifest file should be deleted, if you start a dev server, so the new files are being used, as you wrote.
For that I use two scripts (in the scripts section) in my package.json:

"scripts": {
     "del": "npx rimraf dist/site/templates/assets/js/manifest.json",
    "dev": "npm run del && cross-env NODE_ENV=development vite",
    "build": "npm run del && gulp && cross-env NODE_ENV=production vite build"
  },

I agree with you, that a native option for this would be great and is needed.

@koyadume
Copy link

I could not find any option in docs to specify output directory for dev server. How exactly it can be achieved?

@bluwy
Copy link
Member

bluwy commented Apr 1, 2022

The dev server doesn't output any files, so there's isn't anything to clear, so I'm a bit confused here. If the dist/manifest.json is generated somewhere externally, perhaps you can write a Vite plugin to auto delete that too. Closing as this is a userland issue.

@bluwy bluwy closed this as completed Apr 1, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants