Skip to content

Commit 145d961

Browse files
authored
Merge pull request #116 from timlrx/v2
Add back code splitting
2 parents f6ba3d8 + 37ddbcd commit 145d961

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

.changeset/pre.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"tall-rocks-hear",
2020
"tricky-carpets-fly",
2121
"unlucky-keys-join",
22-
"weak-swans-heal"
22+
"weak-swans-heal",
23+
"yellow-ligers-sort"
2324
]
2425
}

.changeset/yellow-ligers-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pliny': patch
3+
---
4+
5+
Add back code splitting and add use client at the chunk level

packages/pliny/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# pliny
22

3+
## 0.1.0-beta.8
4+
5+
### Patch Changes
6+
7+
- 1fe37b1: Add back code splitting and add use client at the chunk level
8+
39
## 0.1.0-beta.7
410

511
### Patch Changes

packages/pliny/add-use-client.mjs

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
import fs from 'fs'
22
import globby from 'globby'
33

4-
// Append "use client" to client side components
4+
// Append "use client" to all path chunks that contain "use" hooks
55
// So these packages can be directly used in Next.js directly
6+
// This allows us to see support file splitting with easy next import
67
;(async () => {
7-
const clientPaths = await globby([
8-
'comments/Disqus.js',
9-
'comments/Giscus.js',
10-
'comments/Utterances.js',
11-
'search/Algolia.js',
12-
'search/KBar.js',
13-
'search/KBarModal.js',
14-
'search/KBarPortal.js',
15-
'ui/NewsletterForm.js',
16-
'ui/Pre.js',
17-
])
18-
for (const path of clientPaths) {
19-
const data = fs.readFileSync(path)
20-
const fd = fs.openSync(path, 'w+')
21-
const insert = Buffer.from('"use client"\n')
22-
fs.writeSync(fd, insert, 0, insert.length, 0)
23-
fs.writeSync(fd, data, 0, data.length, insert.length)
24-
fs.close(fd, (err) => {
25-
if (err) throw err
26-
})
8+
console.log('Added use client directive to the following files:')
9+
const chunkPaths = await globby('chunk*')
10+
for (const path of chunkPaths) {
11+
const data = fs.readFileSync(path, 'utf8')
12+
if (/useState|useEffect|useRef|useCallback|useMemo|useTheme|useRouter/.test(data)) {
13+
console.log(path)
14+
const insert = Buffer.from('"use client"\n')
15+
fs.writeFileSync(path, insert + data)
16+
}
2717
}
2818
})()

packages/pliny/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pliny",
33
"description": "Main entry point for pliny components",
44
"homepage": "https://github.com/timlrx/pliny",
5-
"version": "0.1.0-beta.7",
5+
"version": "0.1.0-beta.8",
66
"type": "module",
77
"exports": {
88
"./*": "./*",

packages/pliny/tsup.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from 'tsup'
33
export default defineConfig({
44
entry: ['src/**/*'],
55
format: 'esm',
6-
splitting: false,
6+
splitting: true,
77
treeshake: true,
88
dts: true,
99
silent: true,

0 commit comments

Comments
 (0)