diff --git a/docs/config/index.md b/docs/config/index.md index 033fa1e9751e..4c182bc173b8 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -136,7 +136,7 @@ You will not be able to edit your `node_modules` code for debugging, since the c #### deps.external - **Type:** `(string | RegExp)[]` -- **Default:** `['**/node_modules/**', '**/dist/**']` +- **Default:** `[]` Externalize means that Vite will bypass the package to native Node. Externalized dependencies will not be applied Vite's transformers and resolvers, so they do not support HMR on reload. Typically, packages under `node_modules` are externalized. diff --git a/packages/vite-node/src/externalize.ts b/packages/vite-node/src/externalize.ts index fe5fc3202907..93ccbef49695 100644 --- a/packages/vite-node/src/externalize.ts +++ b/packages/vite-node/src/externalize.ts @@ -140,7 +140,7 @@ function matchExternalizePattern(id: string, patterns?: (string | RegExp)[] | tr return true for (const ex of patterns) { if (typeof ex === 'string') { - if (id.includes(`/node_modules/${ex}/`)) + if (id.includes(`/${ex.replace(/(^\/?|\/?$)/g, '')}/`)) return true } else {