build: add production/development export conditions #9977
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Nitro, we create a minimal
node_modules/
just for our final output. This traces the files that are used, respecting the correct export conditions.At the moment,
NODE_ENV
governs whether we load the prod/dev CJS versions of the Vue packages. However, we can support custom export conditions likeproduction
anddevelopment
(see nodejs reference). These have broad community support and can be used on the CLI (for example, withnode --conditions=development index.js
) and by bundlers like Nitro which have support for them.This PR adds production/development conditions for the Node/CJS bundles. To make it backwards compatible it:
./*
as a subpath export so any file that was previously fully specified can continue to be fully specified (e.g.@vue/compiler-core/package.json
default
condition that falls back the previous behaviour (e.g. if no production/development condition is explicitly specified)I've tested this with Nuxt (see repo and Stackblitz). It enables us to reduce the output bundle by 1.2Mb.
Related nitrojs/nitro#2046