This repository was archived by the owner on Aug 7, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { loader } from "webpack" ;
2
+ import { convertToUnixPath } from "../lib/utils" ;
3
+ import { extname } from "path" ;
4
+
5
+ const extMap = {
6
+ ".css" : "style" ,
7
+ ".scss" : "style" ,
8
+ ".less" : "style" ,
9
+ ".js" : "script" ,
10
+ ".ts" : "script" ,
11
+ ".xml" : "markup" ,
12
+ ".html" : "markup" ,
13
+ }
14
+
15
+ const loader : loader . Loader = function ( source , map ) {
16
+ const moduleRelativePath = this . resourcePath . replace ( this . rootContext , "." ) ;
17
+ const modulePath = convertToUnixPath ( moduleRelativePath ) ;
18
+ const ext = extname ( modulePath ) . toLowerCase ( ) ;
19
+ const typeStyle = extMap [ ext ] || "unknown" ;
20
+
21
+ const hotCode = `
22
+ if (module.hot && global._shouldAutoAcceptModule && global._shouldAutoAcceptModule(module.id)) {
23
+ console.log("AUTO ACCEPT MODULE: ", module.id, '${ modulePath } ')
24
+ module.hot.accept();
25
+ module.hot.dispose(() => {
26
+ global.hmrRefresh({ type: '${ typeStyle } ', path: '${ modulePath } ' });
27
+ })
28
+ }` ;
29
+
30
+ this . callback ( null , `${ source } ;${ hotCode } ` , map ) ;
31
+ } ;
32
+
33
+ export default loader ;
34
+
35
+
36
+
You can’t perform that action at this time.
0 commit comments