-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from timlrx/v2
Add back code splitting
- Loading branch information
Showing
6 changed files
with
26 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'pliny': patch | ||
--- | ||
|
||
Add back code splitting and add use client at the chunk level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,18 @@ | ||
import fs from 'fs' | ||
import globby from 'globby' | ||
|
||
// Append "use client" to client side components | ||
// Append "use client" to all path chunks that contain "use" hooks | ||
// So these packages can be directly used in Next.js directly | ||
// This allows us to see support file splitting with easy next import | ||
;(async () => { | ||
const clientPaths = await globby([ | ||
'comments/Disqus.js', | ||
'comments/Giscus.js', | ||
'comments/Utterances.js', | ||
'search/Algolia.js', | ||
'search/KBar.js', | ||
'search/KBarModal.js', | ||
'search/KBarPortal.js', | ||
'ui/NewsletterForm.js', | ||
'ui/Pre.js', | ||
]) | ||
for (const path of clientPaths) { | ||
const data = fs.readFileSync(path) | ||
const fd = fs.openSync(path, 'w+') | ||
const insert = Buffer.from('"use client"\n') | ||
fs.writeSync(fd, insert, 0, insert.length, 0) | ||
fs.writeSync(fd, data, 0, data.length, insert.length) | ||
fs.close(fd, (err) => { | ||
if (err) throw err | ||
}) | ||
console.log('Added use client directive to the following files:') | ||
const chunkPaths = await globby('chunk*') | ||
for (const path of chunkPaths) { | ||
const data = fs.readFileSync(path, 'utf8') | ||
if (/useState|useEffect|useRef|useCallback|useMemo|useTheme|useRouter/.test(data)) { | ||
console.log(path) | ||
const insert = Buffer.from('"use client"\n') | ||
fs.writeFileSync(path, insert + data) | ||
} | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters