File tree Expand file tree Collapse file tree 6 files changed +4027
-52
lines changed Expand file tree Collapse file tree 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 33 "version" : " 1.0.0" ,
44 "description" : " Tweak Vue components written in JSX in real time." ,
55 "main" : " dist/index.js" ,
6- "scripts" : {},
6+ "scripts" : {
7+ "build" : " tsc"
8+ },
79 "files" : [
810 " dist"
911 ],
2426 "homepage" : " https://github.com/Amour1688/vue-jsx-hot-loader#readme" ,
2527 "dependencies" : {
2628 "@babel/parser" : " ^7.0.0" ,
29+ "@babel/template" : " ^7.0.0" ,
2730 "@babel/traverse" : " ^7.0.0" ,
2831 "hash-sum" : " ^2.0.0" ,
2932 "loader-utils" : " ^2.0.0"
3033 },
3134 "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" ,
3340 "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"
3544 }
3645}
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' ;
25import * as parser from "@babel/parser" ;
36import traverse from "@babel/traverse" ;
47
58export default function loader (
69 this : webpack . loader . LoaderContext ,
7- source : string
8- ) : string {
10+ source : string ,
11+ sourceMap : string
12+ ) {
913 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+ ) ;
1236} ;
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