File tree 6 files changed +4027
-52
lines changed
6 files changed +4027
-52
lines changed Original file line number Diff line number Diff line change
1
+ import { createApp } from 'vue' ;
2
+
Original file line number Diff line number Diff line change 3
3
"version" : " 1.0.0" ,
4
4
"description" : " Tweak Vue components written in JSX in real time." ,
5
5
"main" : " dist/index.js" ,
6
- "scripts" : {},
6
+ "scripts" : {
7
+ "build" : " tsc"
8
+ },
7
9
"files" : [
8
10
" dist"
9
11
],
24
26
"homepage" : " https://github.com/Amour1688/vue-jsx-hot-loader#readme" ,
25
27
"dependencies" : {
26
28
"@babel/parser" : " ^7.0.0" ,
29
+ "@babel/template" : " ^7.0.0" ,
27
30
"@babel/traverse" : " ^7.0.0" ,
28
31
"hash-sum" : " ^2.0.0" ,
29
32
"loader-utils" : " ^2.0.0"
30
33
},
31
34
"devDependencies" : {
32
- "@types/webpack" : " ^4.41.22" ,
35
+ "@babel/core" : " ^7.12.10" ,
36
+ "@types/loader-utils" : " ^2.0.1" ,
37
+ "@vue/babel-plugin-jsx" : " ^1.0.0" ,
38
+ "babel-loader" : " ^8.2.2" ,
39
+ "jest" : " ^26.6.3" ,
33
40
"typescript" : " ^4.0.3" ,
34
- "webpack" : " ^4.44.2"
41
+ "vue" : " ^3.0.5" ,
42
+ "webpack" : " ^4.44.2" ,
43
+ "webpack-dev-server" : " ^3.11.1"
35
44
}
36
45
}
Original file line number Diff line number Diff line change 1
- import webpack from 'webpack' ;
1
+ import * as webpack from 'webpack' ;
2
+ import * as hash from 'hash-sum' ;
3
+ import * as path from 'path' ;
4
+ import * as loaderUtils from 'loader-utils' ;
2
5
import * as parser from "@babel/parser" ;
3
6
import traverse from "@babel/traverse" ;
4
7
5
8
export default function loader (
6
9
this : webpack . loader . LoaderContext ,
7
- source : string
8
- ) : string {
10
+ source : string ,
11
+ sourceMap : string
12
+ ) {
9
13
const loaderContext = this ;
10
-
11
- return source ;
14
+
15
+ loaderContext . cacheable ?.( ) ;
16
+ const webpackRemainingChain = loaderUtils . getRemainingRequest ( loaderContext ) . split ( '!' ) ;
17
+ const fullPath = webpackRemainingChain [ webpackRemainingChain . length - 1 ] ;
18
+ const filename = path . relative ( process . cwd ( ) , fullPath ) ;
19
+ const hotId = hash ( fullPath ) ;
20
+
21
+ loaderContext . callback (
22
+ null ,
23
+ `${ source }
24
+ /* hot reload */
25
+ if (module.hot) {
26
+ script.__hmrId = "${ hotId } "
27
+ const api = __VUE_HMR_RUNTIME__
28
+ module.hot.accept()
29
+ if (!api.createRecord('${ hotId } ')) {
30
+ api.reload('${ hotId } ', script)
31
+ }
32
+ }
33
+ ` ,
34
+ sourceMap
35
+ ) ;
12
36
} ;
Original file line number Diff line number Diff line change
1
+ declare module 'hash-sum'
Original file line number Diff line number Diff line change
1
+ const babelConfig = {
2
+ plugins : [
3
+ '@vue/babel-plugin-jsx'
4
+ ] ,
5
+ }
6
+
7
+ module . exports = {
8
+ mode : 'development' ,
9
+ entry : {
10
+ app : './examples/index.js' ,
11
+ } ,
12
+ module : {
13
+ rules : [
14
+ {
15
+ test : / \. ( j s | j s x ) $ / ,
16
+ loader : 'babel-loader' ,
17
+ options : babelConfig ,
18
+ }
19
+ ] ,
20
+ } ,
21
+ } ;
You can’t perform that action at this time.
0 commit comments