mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
chore: HMRRuntime injection (wip)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { relative } from "path";
|
||||
import { relative, resolve } from "path";
|
||||
import dedent from "ts-dedent";
|
||||
import fs from 'fs';
|
||||
|
||||
// note: this will bail even if module.hot appears in a comment
|
||||
const MODULE_HOT_RE = /module\.hot/
|
||||
@ -11,6 +12,16 @@ export default function loader(content: string, map: any) {
|
||||
}
|
||||
const opts = this.getOptions();
|
||||
|
||||
// used to inject the HMR runtime into the entry file
|
||||
if(opts.injectHMRRuntime) {
|
||||
const hmrRuntimePath = resolve(__dirname, './hmr.runtime.js')
|
||||
const hmrRuntime = fs.readFileSync(hmrRuntimePath).toString()
|
||||
.split('// ---')[1]
|
||||
.replace('//# sourceMappingURL=hmr.runtime.js.map', '')
|
||||
|
||||
return this.callback(null, `${content}\n${hmrRuntime}`, map)
|
||||
}
|
||||
|
||||
const relativePath = relative(
|
||||
opts.appPath ?? this.rootContext,
|
||||
this.resourcePath
|
||||
|
Reference in New Issue
Block a user