Skip to content

Commit 94c198a

Browse files
committed
feat: pwa supports, and remove load resume plugin
1 parent ce95348 commit 94c198a

File tree

6 files changed

+1791
-129
lines changed

6 files changed

+1791
-129
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react'
2-
import ReactDOM from 'react-dom'
2+
import ReactDOM from 'react-dom/client'
33
import Show from './Show'
44

5-
ReactDOM.render(
5+
ReactDOM.createRoot(document.getElementById('root')!).render(
66
<React.StrictMode>
77
<Show />
88
</React.StrictMode>,
9-
document.getElementById('root'),
109
)

packages/resume/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@
4444
},
4545
"publishConfig": {
4646
"access": "public"
47+
},
48+
"devDependencies": {
49+
"vite-plugin-pwa": "^0.16.5"
4750
}
4851
}

packages/resume/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import path, { isAbsolute } from 'node:path'
22
import process from 'node:process'
33
import type { InlineConfig } from 'vite'
44
import { build, createServer, preview } from 'vite'
5+
import { VitePWA } from 'vite-plugin-pwa'
56
import react from '@vitejs/plugin-react'
67
import minimist from 'minimist'
7-
import { loadResume } from './plugins/loadResume'
88
import { entry } from './plugins/entry'
99

1010
const cwd = process.cwd()
@@ -33,7 +33,7 @@ function getViteConfig() {
3333
entry({
3434
template,
3535
}),
36-
loadResume(),
36+
VitePWA({ registerType: 'autoUpdate' }),
3737
],
3838
}
3939

packages/resume/src/plugins/entry.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'node:path'
2+
import { readFileSync } from 'node:fs'
13
import type { Plugin } from 'vite'
24
import MagicString from 'magic-string'
35

@@ -7,12 +9,24 @@ interface EntryPluginOptions {
79

810
export function entry({ template }: EntryPluginOptions = {}): Plugin {
911
const RESUME_ENTRY = '/RESUME_ENTRY.tsx'
12+
let content = ''
13+
1014
return {
1115
name: 'resume:entry',
16+
configResolved(config) {
17+
content = readFileSync(path.resolve(config.root, 'README.md')).toString()
18+
},
1219
transformIndexHtml: {
1320
enforce: 'pre',
1421
transform() {
1522
return [
23+
{
24+
tag: 'script',
25+
injectTo: 'body-prepend',
26+
children: `
27+
window.__RESUME__ = ${JSON.stringify(content)}
28+
`,
29+
},
1630
{
1731
tag: 'script',
1832
attrs: {
@@ -36,25 +50,24 @@ export function entry({ template }: EntryPluginOptions = {}): Plugin {
3650
}
3751
const ms = new MagicString(`
3852
import React from 'react'
39-
import ReactDOM from 'react-dom'
53+
import ReactDOM from 'react-dom/client'
4054
import { Resume } from '@resumejs/components'
4155
${templateId ? `import CustomizeComponents from '${templateId}'` : ''}
42-
import md from 'virtual:resume'
4356
4457
const Show = () => {
4558
return (
4659
<Resume ${
4760
templateId ? 'components={CustomizeComponents}' : ''
48-
} className="md">{md}</Resume>
61+
} className="md">{window.__RESUME__}</Resume>
4962
)
5063
}
5164
52-
ReactDOM.render(
53-
<React.StrictMode>
54-
<Show />
55-
</React.StrictMode>,
56-
document.getElementById('root')
57-
)
65+
ReactDOM.createRoot(document.getElementById('root'))
66+
.render(
67+
<React.StrictMode>
68+
<Show />
69+
</React.StrictMode>
70+
)
5871
`)
5972

6073
return {

packages/resume/src/plugins/loadResume.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)