Skip to content

Commit ff62e2a

Browse files
committed
fix(bundler-vite): only set client packages in noExternal (close #866)
1 parent ef75351 commit ff62e2a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

packages/@vuepress/bundler-vite/src/plugins/mainPlugin.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ import '@vuepress/client/app'
3535
)
3636
}
3737

38+
// vuepress related packages that include pure esm client code,
39+
// which should not be optimized in dev mode, and should not be
40+
// externalized in build ssr mode
41+
const clientPackages = [
42+
'@vuepress/client',
43+
...app.pluginApi.plugins.map(({ name }) => name),
44+
]
45+
3846
return {
3947
root: app.dir.temp('vite-root'),
4048
base: app.options.base,
@@ -71,20 +79,10 @@ import '@vuepress/client/app'
7179
},
7280
optimizeDeps: {
7381
include: ['@vuepress/shared'],
74-
// packages that include client code, which should not be optimized
75-
exclude: [
76-
'@vuepress/client',
77-
...app.pluginApi.plugins.map(({ name }) => name),
78-
],
82+
exclude: clientPackages,
7983
},
80-
// bundle all dependencies except vue in ssr mode:
81-
// - transform esm modules to cjs, otherwise we may wrongly `require()` esm modules
82-
// - bundle dependencies all together, otherwise we may fail to resolve them with pnpm
83-
// - force externalize vue, because we need to `require('vue')` in node side for ssr usage,
84-
// then we also need vue as peer-dependency when using pnpm
8584
ssr: {
86-
external: ['vue'],
87-
noExternal: [/^(?!(vue)$).*$/],
85+
noExternal: clientPackages,
8886
},
8987
}
9088
},

0 commit comments

Comments
 (0)