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

chore: check and build if outputDir does not exist before preview #11579

Closed
wants to merge 1 commit into from
Closed

chore: check and build if outputDir does not exist before preview #11579

wants to merge 1 commit into from

Conversation

chenfan0
Copy link
Contributor

@chenfan0 chenfan0 commented Jan 4, 2023

Description

If the build operation has not been performed before the preview, the preview server cannot return the corresponding file
Learn in #10564 , throwing an Error where there was none thrown before, and it breaks plugins using configurePreviewServer to customize.
So if preview, outputDir does not exist. Then it will try to execute vite build to build, if there is an error during the build process, it will remind the user as follows
image

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@chenfan0 chenfan0 changed the title chore: check if outputDir exists before preview chore: check and build if outputDir does not exist before preview Jan 4, 2023
const distDir = path.resolve(config.root, config.build.outDir)
const isAlreadyBuild = fs.existsSync(distDir)
if (!isAlreadyBuild) {
const { status, error } = spawn.sync('npx', ['vite', 'build'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should execute vite build within preview. It feels a bit too automatic, and doesn't work for metaframeworks that use preview API but has a different build command too.

I think for now it's better to leave it as-is. If we really want to check, we could see if any plugins implement configurePreviewServer before issuing the warning. We might also want to do that if it's running through the vite preview command, as using the preview API, the consumer could adjust previewServer.httpServer themselves.

@patak-dev
Copy link
Member

I agree with @bluwy here. This is better implemented in frameworks using Vite. Thanks a lot for checking how we could improve Vite here @chenfan0, but we better leave this one for downstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants