Skip to content

Commit

Permalink
Fix optimizing deps for PNPM (#2172)
Browse files Browse the repository at this point in the history
* Fix optimize deps for PNPM

* Changesets
  • Loading branch information
frandiox committed May 30, 2024
1 parent af90c44 commit ca7f288
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-dolls-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Fix optimizing deps when using PNPM.
23 changes: 15 additions & 8 deletions packages/hydrogen/src/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export function hydrogen(pluginOptions: HydrogenPluginOptions = {}): Plugin[] {
config(_, env) {
sharedOptions.command = env.command;

const isHydrogenMonorepo = new URL(
'../../..',
import.meta.url,
).pathname.endsWith('/hydrogen/packages/');

return {
ssr: {
optimizeDeps: {
Expand All @@ -58,20 +63,22 @@ export function hydrogen(pluginOptions: HydrogenPluginOptions = {}): Plugin[] {
'react/jsx-dev-runtime',
'react-dom',
'react-dom/server',
// Remix deps:
'set-cookie-parser',
'cookie',
'@remix-run/server-runtime',
],
},
},
// Vite performs an initial reload after optimizing these dependencies.
// Do it early to avoid the initial reload:
optimizeDeps: {
include: [
'content-security-policy-builder',
'tiny-invariant',
'worktop/cookie',
],
// Avoid optimizing Hydrogen itself in the monorepo
// to prevent caching source code changes:
include: isHydrogenMonorepo
? [
'content-security-policy-builder',
'tiny-invariant',
'worktop/cookie',
]
: ['@shopify/hydrogen'],
},
};
},
Expand Down
5 changes: 0 additions & 5 deletions templates/skeleton/.npmrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
@shopify:registry=https://registry.npmjs.com
progress=false

# Ensure Vite can optimize these deps in PNPM
public-hoist-pattern[]=cookie
public-hoist-pattern[]=set-cookie-parser
public-hoist-pattern[]=content-security-policy-builder

0 comments on commit ca7f288

Please sign in to comment.