TypeScriptToLua plugin that transforms all exported variables in a given file to global declarations.
Can be used as an alternative to tstl-export-as-global. The benefits from switching to this plugin are as follows:
- Saves allocating one table
- Allows you to use
export const FOO = function()instead ofexport function FOO()if you prefer that syntax - All variables are transformed, not just functions
❗ Use this and any code transformation plugin with caution. Mistakes are possible.
local ____exports = {}
____exports.foo = 10
____exports.bar = function(self)
...
end
return ____exportsBecomes:
foo = 10
function bar(self)
...
endRequires TSTL >= 1.22.0.
- Install this plugin
yarn add tstl-export-to-global -D
# or
npm install tstl-export-to-global --save-dev-
Add
tstl-export-to-globaltotstl.luaPluginsintsconfig.json -
Define
match, which will only apply the transformation to files if their input (TypeScript file) path matches.
{
"tstl": {
"luaPlugins": [
+ {
+ "name": "tstl-export-to-global",
+ "match": ".*\\..*script.ts$"
+ }
],
}
}CC0