Skip to content

Commit 6099b01

Browse files
committed
feat: WIP
1 parent b9ad295 commit 6099b01

File tree

9 files changed

+211
-18
lines changed

9 files changed

+211
-18
lines changed

examples/A.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => <div>23411dd</div>;

examples/App.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { defineComponent } from 'vue';
2+
import A from './A';
3+
import { B } from './B';
4+
5+
const App = defineComponent({
6+
data() {
7+
return {
8+
a: 1
9+
}
10+
},
11+
render() {
12+
const { a } = this;
13+
return (
14+
<>
15+
{a}
16+
<div onClick={() => { this.a++; }}>Hello World!!</div>
17+
<A />
18+
<B />
19+
</>
20+
)
21+
}
22+
});
23+
24+
export default App;
25+
26+
if (module.hot) {
27+
App.__hmrId = "${id}"
28+
const api = __VUE_HMR_RUNTIME__
29+
module.hot.accept();
30+
if (!api.createRecord('${id}')) {
31+
api.reload('${id}', App)
32+
}
33+
api.rerender('${id}', App.render);
34+
}

examples/B.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { defineComponent } from 'vue';
2+
3+
const B = defineComponent({
4+
data() {
5+
return {
6+
a: 1
7+
}
8+
},
9+
render() {
10+
const { a } = this;
11+
return <div onClick={() => { this.a++; }}>{a}13</div>;
12+
}
13+
});
14+
15+
export {
16+
B
17+
};
18+
19+
if (module.hot) {
20+
B.__hmrId = "b"
21+
const api = __VUE_HMR_RUNTIME__
22+
module.hot.accept()
23+
if (!api.createRecord('b')) {
24+
api.reload('b', B)
25+
}
26+
api.rerender('b', B.render);
27+
}

examples/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
import { createApp } from 'vue';
2+
import App from './App';
23

4+
createApp(App).mount('#app');

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Demo</title>
6+
</head>
7+
<body>
8+
<div id="app"></div>
9+
<script src="/dist/app.js"></script>
10+
</body>
11+
</html>

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Tweak Vue components written in JSX in real time.",
55
"main": "dist/index.js",
66
"scripts": {
7+
"dev": "webpack-dev-server",
78
"build": "tsc"
89
},
910
"files": [
@@ -40,6 +41,7 @@
4041
"typescript": "^4.0.3",
4142
"vue": "^3.0.5",
4243
"webpack": "^4.44.2",
44+
"webpack-cli": "^3.0.0",
4345
"webpack-dev-server": "^3.11.1"
4446
}
4547
}

src/hotReload.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
export function genHotReloadCode(
22
id: string,
3-
jsxRequest?: string
3+
component: string
44
): string {
55
return `
66
/* hot reload */
77
if (module.hot) {
8-
script.__hmrId = "${id}"
8+
${component}.__hmrId = "${id}"
99
const api = __VUE_HMR_RUNTIME__
1010
module.hot.accept()
1111
if (!api.createRecord('${id}')) {
12-
api.reload('${id}', script)
12+
api.reload('${id}', ${component})
1313
}
14-
${jsxRequest ? genTemplateHotReloadCode(id, jsxRequest) : ''}
14+
api.rerender('b', ${component}.render);
1515
}
1616
`
1717
}
18-
19-
function genTemplateHotReloadCode(id: string, request: string) {
20-
return `
21-
module.hot.accept(${request}, () => {
22-
api.rerender('${id}', render)
23-
})
24-
`
25-
};

webpack.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path');
2+
13
const babelConfig = {
24
plugins: [
35
'@vue/babel-plugin-jsx'
@@ -9,6 +11,10 @@ module.exports = {
911
entry: {
1012
app: './examples/index.js',
1113
},
14+
output: {
15+
path: path.resolve(__dirname, './dist'),
16+
publicPath: '/dist/',
17+
},
1218
module: {
1319
rules: [
1420
{
@@ -18,4 +24,12 @@ module.exports = {
1824
}
1925
],
2026
},
27+
devServer: {
28+
historyApiFallback: true,
29+
hot: true,
30+
open: true
31+
},
32+
resolve: {
33+
extensions: ['.jsx', '.js']
34+
}
2135
};

yarn.lock

Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ caseless@~0.12.0:
15951595
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
15961596
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
15971597

1598-
chalk@^2.0.0:
1598+
chalk@^2.0.0, chalk@^2.4.2:
15991599
version "2.4.2"
16001600
resolved "https://r.cnpmjs.org/chalk/download/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
16011601
integrity sha1-zUJUFnelQzPPVBpJEIwUMrRMlCQ=
@@ -1905,7 +1905,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
19051905
safe-buffer "^5.0.1"
19061906
sha.js "^2.4.8"
19071907

1908-
cross-spawn@^6.0.0:
1908+
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
19091909
version "6.0.5"
19101910
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
19111911
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
@@ -2123,6 +2123,11 @@ destroy@~1.0.4:
21232123
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
21242124
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
21252125

2126+
detect-file@^1.0.0:
2127+
version "1.0.0"
2128+
resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-1.0.0.tgz#f0d66d03672a825cb1b73bdb3fe62310c8e552b7"
2129+
integrity sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=
2130+
21262131
detect-newline@^3.0.0:
21272132
version "3.1.0"
21282133
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
@@ -2247,7 +2252,7 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
22472252
dependencies:
22482253
once "^1.4.0"
22492254

2250-
enhanced-resolve@^4.3.0:
2255+
enhanced-resolve@^4.1.1, enhanced-resolve@^4.3.0:
22512256
version "4.3.0"
22522257
resolved "https://r.cnpmjs.org/enhanced-resolve/download/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126"
22532258
integrity sha1-O4BvO/r8HsfeaVUe+TzKRsFwQSY=
@@ -2444,6 +2449,13 @@ expand-brackets@^2.1.4:
24442449
snapdragon "^0.8.1"
24452450
to-regex "^3.0.1"
24462451

2452+
expand-tilde@^2.0.0, expand-tilde@^2.0.2:
2453+
version "2.0.2"
2454+
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
2455+
integrity sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=
2456+
dependencies:
2457+
homedir-polyfill "^1.0.1"
2458+
24472459
expect@^26.6.2:
24482460
version "26.6.2"
24492461
resolved "https://registry.yarnpkg.com/expect/-/expect-26.6.2.tgz#c6b996bf26bf3fe18b67b2d0f51fc981ba934417"
@@ -2638,6 +2650,16 @@ find-up@^4.0.0, find-up@^4.1.0:
26382650
locate-path "^5.0.0"
26392651
path-exists "^4.0.0"
26402652

2653+
findup-sync@^3.0.0:
2654+
version "3.0.0"
2655+
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-3.0.0.tgz#17b108f9ee512dfb7a5c7f3c8b27ea9e1a9c08d1"
2656+
integrity sha512-YbffarhcicEhOrm4CtrwdKBdCuz576RLdhJDsIfvNtxUuhdRet1qZcsMjqbePtAseKdAnDyM/IyXbu7PRPRLYg==
2657+
dependencies:
2658+
detect-file "^1.0.0"
2659+
is-glob "^4.0.0"
2660+
micromatch "^3.0.4"
2661+
resolve-dir "^1.0.1"
2662+
26412663
flush-write-stream@^1.0.0:
26422664
version "1.1.1"
26432665
resolved "https://r.cnpmjs.org/flush-write-stream/download/flush-write-stream-1.1.1.tgz#8dd7d873a1babc207d94ead0c2e0e44276ebf2e8"
@@ -2810,6 +2832,42 @@ glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4:
28102832
once "^1.3.0"
28112833
path-is-absolute "^1.0.0"
28122834

2835+
global-modules@^1.0.0:
2836+
version "1.0.0"
2837+
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea"
2838+
integrity sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==
2839+
dependencies:
2840+
global-prefix "^1.0.1"
2841+
is-windows "^1.0.1"
2842+
resolve-dir "^1.0.0"
2843+
2844+
global-modules@^2.0.0:
2845+
version "2.0.0"
2846+
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780"
2847+
integrity sha512-NGbfmJBp9x8IxyJSd1P+otYK8vonoJactOogrVfFRIAEY1ukil8RSKDz2Yo7wh1oihl51l/r6W4epkeKJHqL8A==
2848+
dependencies:
2849+
global-prefix "^3.0.0"
2850+
2851+
global-prefix@^1.0.1:
2852+
version "1.0.2"
2853+
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-1.0.2.tgz#dbf743c6c14992593c655568cb66ed32c0122ebe"
2854+
integrity sha1-2/dDxsFJklk8ZVVoy2btMsASLr4=
2855+
dependencies:
2856+
expand-tilde "^2.0.2"
2857+
homedir-polyfill "^1.0.1"
2858+
ini "^1.3.4"
2859+
is-windows "^1.0.1"
2860+
which "^1.2.14"
2861+
2862+
global-prefix@^3.0.0:
2863+
version "3.0.0"
2864+
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97"
2865+
integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==
2866+
dependencies:
2867+
ini "^1.3.5"
2868+
kind-of "^6.0.2"
2869+
which "^1.3.1"
2870+
28132871
globals@^11.1.0:
28142872
version "11.12.0"
28152873
resolved "https://r.cnpmjs.org/globals/download/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
@@ -2938,6 +2996,13 @@ hmac-drbg@^1.0.0:
29382996
minimalistic-assert "^1.0.0"
29392997
minimalistic-crypto-utils "^1.0.1"
29402998

2999+
homedir-polyfill@^1.0.1:
3000+
version "1.0.3"
3001+
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
3002+
integrity sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==
3003+
dependencies:
3004+
parse-passwd "^1.0.0"
3005+
29413006
hosted-git-info@^2.1.4:
29423007
version "2.8.8"
29433008
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"
@@ -3121,6 +3186,11 @@ inherits@2.0.3:
31213186
resolved "https://r.cnpmjs.org/inherits/download/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
31223187
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
31233188

3189+
ini@^1.3.4, ini@^1.3.5:
3190+
version "1.3.8"
3191+
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
3192+
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
3193+
31243194
internal-ip@^4.3.0:
31253195
version "4.3.0"
31263196
resolved "https://registry.yarnpkg.com/internal-ip/-/internal-ip-4.3.0.tgz#845452baad9d2ca3b69c635a137acb9a0dad0907"
@@ -3129,6 +3199,11 @@ internal-ip@^4.3.0:
31293199
default-gateway "^4.2.0"
31303200
ipaddr.js "^1.9.0"
31313201

3202+
interpret@^1.4.0:
3203+
version "1.4.0"
3204+
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
3205+
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
3206+
31323207
ip-regex@^2.1.0:
31333208
version "2.1.0"
31343209
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
@@ -3373,7 +3448,7 @@ is-typedarray@^1.0.0, is-typedarray@~1.0.0:
33733448
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
33743449
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=
33753450

3376-
is-windows@^1.0.2:
3451+
is-windows@^1.0.1, is-windows@^1.0.2:
33773452
version "1.0.2"
33783453
resolved "https://r.cnpmjs.org/is-windows/download/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
33793454
integrity sha1-0YUOuXkezRjmGCzhKjDzlmNLsZ0=
@@ -4138,7 +4213,7 @@ methods@~1.1.2:
41384213
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
41394214
integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=
41404215

4141-
micromatch@^3.1.10, micromatch@^3.1.4:
4216+
micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4:
41424217
version "3.1.10"
41434218
resolved "https://r.cnpmjs.org/micromatch/download/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
41444219
integrity sha1-cIWbyVyYQJUvNZoGij/En57PrCM=
@@ -4648,6 +4723,11 @@ parse-json@^5.0.0:
46484723
json-parse-even-better-errors "^2.3.0"
46494724
lines-and-columns "^1.1.6"
46504725

4726+
parse-passwd@^1.0.0:
4727+
version "1.0.0"
4728+
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
4729+
integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=
4730+
46514731
parse5@5.1.1:
46524732
version "5.1.1"
46534733
resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178"
@@ -5118,6 +5198,14 @@ resolve-cwd@^3.0.0:
51185198
dependencies:
51195199
resolve-from "^5.0.0"
51205200

5201+
resolve-dir@^1.0.0, resolve-dir@^1.0.1:
5202+
version "1.0.1"
5203+
resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43"
5204+
integrity sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=
5205+
dependencies:
5206+
expand-tilde "^2.0.0"
5207+
global-modules "^1.0.0"
5208+
51215209
resolve-from@^3.0.0:
51225210
version "3.0.0"
51235211
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
@@ -6103,6 +6191,11 @@ uuid@^8.3.0:
61036191
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
61046192
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
61056193

6194+
v8-compile-cache@^2.1.1:
6195+
version "2.2.0"
6196+
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz#9471efa3ef9128d2f7c6a7ca39c4dd6b5055b132"
6197+
integrity sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==
6198+
61066199
v8-to-istanbul@^7.0.0:
61076200
version "7.1.0"
61086201
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-7.1.0.tgz#5b95cef45c0f83217ec79f8fc7ee1c8b486aee07"
@@ -6204,6 +6297,23 @@ webidl-conversions@^6.1.0:
62046297
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514"
62056298
integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==
62066299

6300+
webpack-cli@^3.0.0:
6301+
version "3.3.12"
6302+
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.12.tgz#94e9ada081453cd0aa609c99e500012fd3ad2d4a"
6303+
integrity sha512-NVWBaz9k839ZH/sinurM+HcDvJOTXwSjYp1ku+5XKeOC03z8v5QitnK/x+lAxGXFyhdayoIf/GOpv85z3/xPag==
6304+
dependencies:
6305+
chalk "^2.4.2"
6306+
cross-spawn "^6.0.5"
6307+
enhanced-resolve "^4.1.1"
6308+
findup-sync "^3.0.0"
6309+
global-modules "^2.0.0"
6310+
import-local "^2.0.0"
6311+
interpret "^1.4.0"
6312+
loader-utils "^1.4.0"
6313+
supports-color "^6.1.0"
6314+
v8-compile-cache "^2.1.1"
6315+
yargs "^13.3.2"
6316+
62076317
webpack-dev-middleware@^3.7.2:
62086318
version "3.7.3"
62096319
resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-3.7.3.tgz#0639372b143262e2b84ab95d3b91a7597061c2c5"
@@ -6339,7 +6449,7 @@ which-module@^2.0.0:
63396449
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
63406450
integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=
63416451

6342-
which@^1.2.9:
6452+
which@^1.2.14, which@^1.2.9, which@^1.3.1:
63436453
version "1.3.1"
63446454
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
63456455
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==

0 commit comments

Comments
 (0)