chore: HMRRuntime injection (wip)

This commit is contained in:
Igor Randjelovic
2021-03-24 17:27:35 +01:00
parent 3a28f9eef6
commit 8855ca4373
13 changed files with 384 additions and 41 deletions

View File

@ -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