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

fix: change the preview default mode from development to production #4483

Merged
merged 1 commit into from
Aug 4, 2021

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Aug 3, 2021

Description

fix #4007

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 Commit 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.

Copy link
Contributor

@hyf0 hyf0 left a comment

Choose a reason for hiding this comment

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

As I describe in #4431, you may also need to set dev always to be true rather config.isProduction.
sirv with dev false seems useless in vite preview.

app.use(
config.base,
sirv(distDir, {
etag: true,
dev: !config.isProduction,
single: true
})
)

@@ -45,7 +45,7 @@ export async function preview(
config.base,
sirv(distDir, {
etag: true,
dev: !config.isProduction,
dev: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Enable "dev" mode, which disables/skips caching. Instead, sirv will traverse the file system on every request.
Additionally, dev mode will ignore maxAge and immutable as these options generate a production-oriented Cache-Control header value. https://github.com/lukeed/sirv/tree/master/packages/sirv#optsdev

I'm not sure to disable sirv dev mode will be good for DX. This will cause if the user uses both yarn build --watch and yarn preview , user have to re-runyarn preview command to refresh server cache to see the newest result.

Copy link
Member Author

Choose a reason for hiding this comment

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

The role of preview is to verify the production environment, so we fix the mode to production.
If it is unstable and still under development, is it more appropriate to use vite dev?

Copy link
Member Author

@ygj6 ygj6 Aug 4, 2021

Choose a reason for hiding this comment

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

Maybe we can change it to --force, the same as vite dev,is it appropriate?

Copy link
Member

Choose a reason for hiding this comment

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

vite preview is not intended to be used for production though, it is just to check locally. So it is fine if the server is in dev mode. We haven't had complaints about this.
There are environments like electron that are using build --watch. The default to me should be dev: true as it was.

Copy link
Member Author

Choose a reason for hiding this comment

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

@patak-js
If so, then vite preview is still in development mode by default, but the user is allowed to change the mode by --mode,right?

Copy link
Contributor

Choose a reason for hiding this comment

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

vite preview should be in production mode by default to fix the issue you mention. I think only call sirv with dev: true will be ok.

@ygj6
Copy link
Member Author

ygj6 commented Aug 4, 2021

You are right, mode is really useless in Preview,I have fixed it to production.

@ygj6
Copy link
Member Author

ygj6 commented Aug 4, 2021

@patak-js @iheyunfei
Thank you, I have modified it, help review.

@antfu antfu merged commit 77933ba into vitejs:main Aug 4, 2021
matbarker added a commit to matbarker/vite that referenced this pull request Sep 14, 2021
As per this pull request -- vitejs#4483 --, the default mode for `preview` is now `production`
@@ -217,7 +217,7 @@ cli
}
},
'serve',
Copy link
Member

Choose a reason for hiding this comment

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

Should this line be changed to build too? Because we don't actually need vite server plugins in vite preview.

aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
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.

base path in preview command doesn't match build command
5 participants