diff --git a/docs/configuration.md b/docs/configuration.md index 624e2520..fa672273 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -23,18 +23,19 @@ You can use our [VS Code extension](editor-support.md) or manually specify the J } ``` -| Option | Values | Description | -| -------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `luaTarget` | `"JIT"`, `"5.3"`, `"5.2"`, `"5.1"`, `"universal"` (default: `"universal"`) | Specifies the Lua version you want to generate code for. Choosing `universal` makes TypeScriptToLua generate code compatible with all supported Lua targets. | -| `noImplicitSelf` | `true`, `false` (default: `false`) | If true, treats all project files as if they were prefixed with
`/** @noSelfInFile **/`. | -| `noHeader` | `true`, `false` (default: `false`) | Set this to true if you don't want to include our header in the output. | -| `luaLibImport` | `"inline"`, `"require"`, `"always"`, `"none"` (default: `"require"`) | We polyfill certain JavaScript features with Lua functions, this option specifies how these functions are imported into the Lua output. | -| `sourceMapTraceback` | `true`, `false` (default: `false`) | Overrides Lua's `debug.traceback` to apply sourcemaps to Lua stacktraces. This will make error messages point to your original TypeScript code instead of the generated Lua. | -| `luaBundle` | File path (relative to the `tsconfig.json`) | Will bundle all output lua files into a single bundle file. Requires **luaBundleEntry** to be set! | -| `luaBundleEntry` | File path (relative to the `tsconfig.json`) | This should be the name/path of the TS file in your project that will serve as entry point to the bundled code. | -| `luaPlugins` | `Array<{ name: string; import?: string }>` | List of [TypeScriptToLua plugins](api/plugins.md). | -| `buildMode` | `"default"`, `"library"` (default: `"library"`) | Use `buildMode: "library"` to build [publishable library packages](publishing-modules.md). | -| `tstlVerbose` | `true`, `false` (default: `false`) | Output additional logging when performing a tstl build, to help diagnose issues. | +| Option | Values | Description | +| -------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `luaTarget` | `"JIT"`, `"5.3"`, `"5.2"`, `"5.1"`, `"universal"` (default: `"universal"`) | Specifies the Lua version you want to generate code for. Choosing `universal` makes TypeScriptToLua generate code compatible with all supported Lua targets. | +| `noImplicitSelf` | `true`, `false` (default: `false`) | If true, treats all project files as if they were prefixed with
`/** @noSelfInFile **/`. | +| `noHeader` | `true`, `false` (default: `false`) | Set this to true if you don't want to include our header in the output. | +| `luaLibImport` | `"inline"`, `"require"`, `"always"`, `"none"` (default: `"require"`) | We polyfill certain JavaScript features with Lua functions, this option specifies how these functions are imported into the Lua output. | +| `sourceMapTraceback` | `true`, `false` (default: `false`) | Overrides Lua's `debug.traceback` to apply sourcemaps to Lua stacktraces. This will make error messages point to your original TypeScript code instead of the generated Lua. | +| `luaBundle` | File path (relative to the `tsconfig.json`) | Will bundle all output lua files into a single bundle file. Requires **luaBundleEntry** to be set! | +| `luaBundleEntry` | File path (relative to the `tsconfig.json`) | This should be the name/path of the TS file in your project that will serve as entry point to the bundled code. | +| `luaPlugins` | `Array<{ name: string; import?: string }>` | List of [TypeScriptToLua plugins](api/plugins.md). | +| `buildMode` | `"default"`, `"library"` (default: `"library"`) | Use `buildMode: "library"` to build [publishable library packages](publishing-modules.md). | +| `tstlVerbose` | `true`, `false` (default: `false`) | Output additional logging when performing a tstl build, to help diagnose issues. | +| `noResolvePaths` | `Array` | An array of require paths that will **NOT** be resolved. For example `["require1", "sub.require2"]` will stop tstl from trying to resolve Lua sources for `require("require1")` and `require("sub.require2")`. | ## Standard options diff --git a/docs/json-modules.md b/docs/json-modules.md new file mode 100644 index 00000000..ea1b0628 --- /dev/null +++ b/docs/json-modules.md @@ -0,0 +1,50 @@ +--- +title: Importing JSON Modules +--- + +TypeScriptToLua supports importing JSON files into your TypeScript. This is done by translating the JSON file to Lua and simply including this Lua file as part of the transpiler output. + +# Example + +Consider the following project files: + +``` +./ +├── main.ts +├── myjsondata.json +└── tsconfig.json +``` + +## Modifying tsconfig.json + +To be able to import JSON files you have to enable the `resolveJsonModule` option in tsconfig.json, and set `moduleResolution` to node: + +```json title=tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "resolveJsonModule": true + } +} +``` + +## Json data + +The file containing JSON is just standard JSON: + +```json title=myjsondata.json +{ + "property1": "foo", + "property2": "bar" +} +``` + +## Importing JSON data + +Now to access your data, simply import it from your TS file: + +```ts title=main.ts +import * as myJson from "./myjsondata.json"; + +const p1 = myJson.property1; +``` diff --git a/sidebars.json b/sidebars.json index 2446d13f..21559104 100644 --- a/sidebars.json +++ b/sidebars.json @@ -10,6 +10,7 @@ "advanced/writing-declarations", "advanced/compiler-annotations", "advanced/language-extensions", + "json-modules", "jsx", { "type": "category",