Is there a way to build and inject a file inside a webpack loader? I want to make an HTML loader which replaces a string with a url of an emitted file i build inside the loader.
module.exports = function (source) {
// source = html file content
const tsFilename = 'foo.ts'
// I want to load and build `foo.ts` file, rules for this have been configured in webpack
const tsSource = 'source parsed file'
this.emitFile('output.js', tsSource)
source.replace('__JS_FILE__', 'output.js')
return source
}
Using loadModule
only returns the source code but will not compile the file. I thought about using something like a childCompiler, but no idea how this should work.