I have a TypeScript module that uses Lua code from an external .lua file to do some adapter magic. I include this Lua code stringified in the JavaScript and then use 'lua-in-js' package to execute it. I use the 'fs' module to read the file with fs.readFileSync and then I stringify the result like this. (See module.ts below.)
const luaCode = fs.readFileSync('./adapter.lua').toString()
However, the challenge is that this TypeScript module is used in React Native, where the 'fs' package is not supported. I use 'tsc' to compile the module bundle, but in the compiled code, the 'fs' module is included and used as a dependency. (See bundle.js below.)
const fs_1 = require("fs");
const luaCode = (0, fs_1.readFileSync)('./adapter.lua').toString();
When trying to run the code it crashes because 'fs' is not supported in RN. So the Lua code would have to be included in the bundle file in its entirety inside the string variable luaCode. How can I achieve this? Below is also my tsconfig.json for reference.
{
"compilerOptions": {
"target": "ES2015",
"module": "commonjs",
"declaration": true,
"outDir": "lib",
"strict": true,
"removeComments": true,
"skipLibCheck": true,
"isolatedModules": true
},
"include": [
"src/**/*"
]
}