-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
build: use cjs/mjs extensions for cjs/esm builds #4814
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
base: main
Are you sure you want to change the base?
Conversation
'use strict' | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./dist/compiler-dom.prod.cjs') |
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.
I would suggest adding conditional exports at the same time so instead of process.env
workaround, we can use import conditions to use dev or prod build
This is indeed a breaking change.
However, with Node's ESM <> CJS interop, current |
Recently, an SSR issue was opened on vue-i18n with the combination of vitepress v1 alpha10 + vue-i18n. Using the stacktrace output as a clue, I’ve found out the cause, I found the issue occurred in the vitepress build, i.e., the build of vite's SSR. Since vue-i18n is integrated using the vue-devtools plugin, it depends on vue's The reason for using this flag is that we want to tree-shake the vue-devtools plugin code implemented in vue-i18n for production. In vite's SSR builds, the Vue-related modules loaded are cjs modules such as The So, vitepress SSR uses runtime-core for cjs, so if you create an SSG application using vue-i18n, it will not work because the To solve this issue, I might be able to work around a bundle hack like vue-router on the vue-i18n side. |
Thanks for sharing this @kazupon. This is off topic just to share, in nuxt 3, we set It would be amazing if mjs build output can use ESM conditions to somehow switch between prod build with/without bundler flag because this way we can externaliz libs for production SSR build without stubing devtools dependency. |
@pi0 Thank you for all your helpful sharing as always! 💚 |
NOTE: This fix is workaround for vite3 SSR. Ideally, We hope that this fix will not be necessary once the SSR module on the vue side supports cjs/mjs. ref: vuejs/core#4814
NOTE: This fix is workaround for vite3 SSR. Ideally, We hope that this fix will not be necessary once the SSR module on the vue side supports cjs/mjs. ref: vuejs/core#4814
Summary
This PR proposes using
.cjs
and.mjs
instead of the current.js
extensions. That will allow usage of the@vue
packages in a native Node module context.Example
Notes
Background issue
This will improve support for use of vue dependencies in native node esm contexts.