-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Conversation
There was a problem hiding this 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
.
vite/packages/vite/src/node/preview.ts
Lines 44 to 51 in 690b35e
app.use( | |
config.base, | |
sirv(distDir, { | |
etag: true, | |
dev: !config.isProduction, | |
single: true | |
}) | |
) |
packages/vite/src/node/preview.ts
Outdated
@@ -45,7 +45,7 @@ export async function preview( | |||
config.base, | |||
sirv(distDir, { | |||
etag: true, | |||
dev: !config.isProduction, | |||
dev: false, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
You are right, |
@patak-js @iheyunfei |
As per this pull request -- vitejs#4483 --, the default mode for `preview` is now `production`
@@ -217,7 +217,7 @@ cli | |||
} | |||
}, | |||
'serve', |
There was a problem hiding this comment.
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
.
Description
fix #4007
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).