A TypeScriptToLua plugin that in-lines image imports.
Add the plugin
yarn add -D love-inline-import
# or npm install -D love-inline-import
Register the plugin in your tsconfig.json
{
"tstl": {
"luaPlugins": [
{ "name": "love-inline-import" }
]
}
}
Tell TypeScript that a png import returns an Image
type
// add this ambient code to a file within your project
// this tells TypeScript that imports ending with .png
// are expected to return an image type
declare module "*.png" {
import { Image } from "love.graphics";
const image: Image;
export = image;
}
And you're good to go! Here's some sample input and output code
import * as player from "./player.png";
love.draw = () => {
love.graphics.draw(player);
};
local player = love.graphics.newImage(...) -- ... is generated and contains image data
love.draw = function()
love.graphics.draw(player)
end
- Allows images to be stored in your source directory
- Image resolution is handled on compilation