Created
February 14, 2024 15:20
-
-
Save LukasBombach/0987a711fe1e11ff6c200b47bc244a90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CompileToStringPlugin { | |
constructor() { | |
this.PLUGIN_NAME = this.constructor.name; | |
} | |
apply(compiler) { | |
if (!this.options.isServer) { | |
compiler.hooks.normalModuleFactory.tap(this.PLUGIN_NAME, nmf => { | |
nmf.hooks.beforeResolve.tap(this.PLUGIN_NAME, result => { | |
// how can I use webpack here to compile the file result.request | |
// with its dependencies to and get the resulting source | |
// so that I can return the sourcecode as export | |
const compiledSourceCode = compileAndBundle(result.request); | |
return `module.exports = ${JSON.stringify(compiledSourceCode)}`; | |
}); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment