diff --git a/packages/node-resolve/README.md b/packages/node-resolve/README.md index 6866a6853..11f5b5dc0 100755 --- a/packages/node-resolve/README.md +++ b/packages/node-resolve/README.md @@ -53,7 +53,7 @@ This plugin supports the package entrypoints feature from node js, specified in Type: `Array[...String]`
Default: `[]` -Additional conditions of the package.json exports field to match when resolving modules. By default, this plugin looks for the `['default', 'module', 'import']` conditions when resolving imports. +Additional conditions of the package.json exports field to match when resolving modules. By default, this plugin looks for the `['default', 'module', 'import', 'development|production']` conditions when resolving imports. If neither the `development` or `production` conditions are provided it will default to `production` - or `development` if `NODE_ENV` is set to a value other than `production`. When using `@rollup/plugin-commonjs` v16 or higher, this plugin will use the `['default', 'module', 'require']` conditions when resolving require statements. diff --git a/packages/node-resolve/src/index.js b/packages/node-resolve/src/index.js index a675247aa..3cf0caa3a 100644 --- a/packages/node-resolve/src/index.js +++ b/packages/node-resolve/src/index.js @@ -52,8 +52,17 @@ export function nodeResolve(opts = {}) { const options = { ...defaults, ...opts }; const { extensions, jail, moduleDirectories, modulePaths, ignoreSideEffectsForRoot } = options; - const conditionsEsm = [...baseConditionsEsm, ...(options.exportConditions || [])]; - const conditionsCjs = [...baseConditionsCjs, ...(options.exportConditions || [])]; + const exportConditions = options.exportConditions || []; + const devProdCondition = + exportConditions.includes('development') || exportConditions.includes('production') + ? [] + : [ + process.env.NODE_ENV && process.env.NODE_ENV !== 'production' + ? 'development' + : 'production' + ]; + const conditionsEsm = [...baseConditionsEsm, ...exportConditions, ...devProdCondition]; + const conditionsCjs = [...baseConditionsCjs, ...exportConditions, ...devProdCondition]; const packageInfoCache = new Map(); const idToPackageInfo = new Map(); const mainFields = getMainFields(options);