Inlining the string result of a function call which uses fs during transpilation #11831
Unanswered
janus-reith
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You might try |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to find out how to inline calls to a function called
importAsString
, which makes use of fs.readFileSync (andcallsite
to get which file called it to resolve the path) so it is replaced with the actual result string during transpilation.https://github.com/reactioncommerce/api-utils/blob/trunk/lib/importAsString.js
That
importAsString
function is imported across other modules, which in turn I am importing in some next.js api routes.For example: https://github.com/reactioncommerce/api-plugin-shops/blob/a44fe9cccf958a3a552ce25e1602d1b1e0b00e84/src/schemas/index.js#L3
The current webpack configuration I have in a nextjs project will inline that
importAsString
method, but the files it tries to import won't be present, and can't be found anymore as they were relative to the function calling it.I'm trying to find out how I could utilize babel to directly read the files and inline them as strings everywhere
importAsString
is used.So far I had no luck with babel-plugin-static-fs or brfs-babel, I assume that is because
fs.readFileSync
is not used directly, but inside some function of a module, so it can't be statically replaced.Therefore, instead of diving into that logic, I was considering to just replace that
importAsString
function call altogether with the resulting string, similar to howbabel-plugin-static-fs
replaces calls tofs.readFileSync
with inlined strings.Except if someone might know another approach for this which I could use instead to retain that proper reference?
Would appreciate any hints or ideas on how to accomplish this, or which alternatives to consider!
Beta Was this translation helpful? Give feedback.
All reactions