Skip to content

Commit

Permalink
fix(resolve): prioritize browser field
Browse files Browse the repository at this point in the history
fix #1154
  • Loading branch information
yyx990803 committed Jan 2, 2021
1 parent e27fe30 commit dfef3de
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -20,7 +20,7 @@ import { createFilter } from '@rollup/pluginutils'
import { PartialResolvedId } from 'rollup'
import isBuiltin from 'isbuiltin'

const mainFields = ['module', 'jsnext', 'jsnext:main', 'browser', 'main']
const mainFields = ['browser', 'module', 'jsnext', 'jsnext:main', 'main']

const isDebug = process.env.DEBUG
const debug = createDebugger('vite:resolve-details', {
Expand Down Expand Up @@ -403,7 +403,9 @@ function resolveConditionalExports(exp: any): string | undefined {
if (typeof exp === 'string') {
return exp
} else if (isObject(exp)) {
if (typeof exp.import === 'string') {
if (typeof exp.browser === 'string') {
return exp.browser
} else if (typeof exp.import === 'string') {
return exp.import
} else if (typeof exp.default === 'string') {
return exp.default
Expand Down

0 comments on commit dfef3de

Please sign in to comment.