Install monaco-themes
masterYou can install monaco-themes using npm, pnpm, or yarn to use theme definitions with the Monaco Editor in the browser.
npm install monaco-themes
# or
pnpm add monaco-themes
# or
yarn add monaco-themesrepository·master·Indexed 19 days ago
https://github.com/brijeshb42/monaco-themesA collection of theme definitions and utilities for integrating color themes into the Monaco Editor in web browsers. It includes the parseTmTheme() function to convert TextMate (.tmTheme) files into Monaco-compatible JSON objects, handling base detection, color normalization, and scope mapping. The library supports ESM, CommonJS, and IIFE build formats for use with modern bundlers or direct <script> tag integration.
You can install monaco-themes using npm, pnpm, or yarn to use theme definitions with the Monaco Editor in the browser.
npm install monaco-themes
# or
pnpm add monaco-themes
# or
yarn add monaco-themesIf you are using Vite, Webpack, or similar bundlers, you can import the pre-generated JSON theme files directly from the monaco-themes/themes/ path.
const monaco =
/* import monaco */
import('monaco-themes/themes/Monokai.json').then((data) => {
monaco.editor.defineTheme('monokai', data.default || data);
monaco.editor.setTheme('monokai');
});You can host the themes directory from this repository in your own project and load the JSON files using the standard fetch API.
/* load monaco */
fetch('/themes/Monokai.json')
.then((data) => data.json())
.then((data) => {
monaco.editor.defineTheme('monokai', data);
monaco.editor.setTheme('monokai');
});For direct browser usage without a bundler, include the library via unpkg. The library is exposed under the global MonacoThemes object.
<script
type="text/javascript"
src="https://unpkg.com/monaco-themes/dist/monaco-themes.js"
></script>
<script type="text/javascript">
var tmThemeString = /* read using FileReader */
var themeData = MonacoThemes.parseTmTheme(tmThemeString);
monaco.editor.defineTheme('mytheme', themeData);
monaco.editor.setTheme('mytheme');
</script>If your environment does not support ESM, you can use the CommonJS pattern to import parseTmTheme.
const { parseTmTheme } = require('monaco-themes');
const tmThemeString = /* read using FileReader */
const themeData = parseTmTheme(tmThemeString);
monaco.editor.defineTheme('mytheme', themeData);
monaco.editor.setTheme('mytheme');The parseTmTheme function converts a TextMate theme string into a JSON object compatible with monaco.editor.defineTheme. This is the recommended way to transform raw theme files into Monaco-compatible formats.
import { parseTmTheme } from 'monaco-themes';
const tmThemeString = /* read using FileReader */
const themeData = parseTmTheme(tmThemeString);
monaco.editor.defineTheme('mytheme', themeData);
monaco.editor.setTheme('mytheme');The monaco-themes project uses tsdown to generate multiple build formats (ESM, CJS, and IIFE). The configuration defines a commonConfig object applied to all builds, which includes settings for cleaning the output directory, generating sourcemaps, targeting the browser platform, and enabling tree-shaking. It also injects a license banner into the generated JavaScript files using metadata from package.json.
import { defineConfig, type UserConfig } from 'tsdown';
const commonConfig: UserConfig = {
clean: true,
sourcemap: true,
platform: 'browser',
treeshake: true,
skipNodeModulesBundle: true,
env: {
NODE_ENV: 'production',
},
banner: {
js: `/**
* monaco-themes v0.4.8
* (c) 2026 Brijesh
* @license MIT
*/`
}
};The parseTmTheme function converts a raw TextMate (.tmTheme) file string into a MonacoTheme object compatible with the Monaco Editor API. It parses the Property List (plist) content, maps TextMate scopes to Monaco rules, and translates global color settings (like foreground, background, and selection) into Monaco's color configuration format.
Key behaviors:
vs-dark or vs base by analyzing the darkness of the editor.background color.foreground, selection) to Monaco keys (e.g., editor.foreground, editor.selectionBackground).Refer to the Monaco Editor documentation for the expected structure of the returned object.
import { parseTmTheme } from 'monaco-themes';
const rawTmThemeString = `... contents of a .tmTheme file ...`;
const monacoTheme = parseTmTheme(rawTmThemeString);
// Use the resulting object with Monaco Editor
// monaco.editor.defineTheme('myTheme', monacoTheme);The project produces three distinct build targets via tsdown:
src/index.ts and it generates TypeScript declaration files (dts: true).<script> tags. The entry point is src/index.ts, the output filename is monaco-themes, and it exposes a global variable named MonacoThemes. This build does not generate declaration files (dts: false).For the IIFE build, external dependencies like fast-plist are mapped to the global FastPlist.
export default defineConfig([
// ESM/CJS build
{
entry: { index: 'src/index.ts' },
format: ['esm', 'cjs'],
dts: true,
},
// IIFE build
{
entry: { 'monaco-themes': 'src/index.ts' },
globalName: 'MonacoThemes',
format: 'iife',
dts: false,
outputOptions: {
globals: {
'fast-plist': 'FastPlist',
},
},
},
]);The MonacoTheme interface defines the structure required by the Monaco Editor to apply a custom theme. This interface is the output of parseTmTheme.
| Property | Type | Description |
|---|---|---|
base | 'vs-dark' | 'vs' | The base theme to inherit from. |
inherit | boolean | Whether to inherit from the base theme. |
rules | Array<{ token: string; foreground?: string; background?: string; fontStyle?: string; }> | An array of token rules mapping scopes to styles. |
colors | Record<string, string> | A dictionary of editor UI colors (e.g., editor.background). |
export interface MonacoTheme {
base: 'vs-dark' | 'vs';
inherit: boolean;
rules: {
token: string;
foreground?: string;
background?: string;
fontStyle?: string;
}[];
colors: Record<string, string>;
}