{"id":13727093,"url":"https://github.com/lukeed/svelte-preprocess-esbuild","last_synced_at":"2025-10-09T18:23:53.949Z","repository":{"id":44422480,"uuid":"321803614","full_name":"lukeed/svelte-preprocess-esbuild","owner":"lukeed","description":"A Svelte Preprocessor to compile TypeScript via esbuild!","archived":false,"fork":false,"pushed_at":"2022-08-28T04:02:37.000Z","size":50,"stargazers_count":45,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-22T22:10:04.067Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-15T22:23:28.000Z","updated_at":"2024-07-10T15:24:30.000Z","dependencies_parsed_at":"2022-09-07T13:40:10.689Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/svelte-preprocess-esbuild","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fsvelte-preprocess-esbuild","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fsvelte-preprocess-esbuild/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fsvelte-preprocess-esbuild/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fsvelte-preprocess-esbuild/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/svelte-preprocess-esbuild/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252965207,"owners_count":21832838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:03:39.192Z","updated_at":"2025-10-09T18:23:48.927Z","avatar_url":"https://github.com/lukeed.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# svelte-preprocess-esbuild [![CI](https://github.com/lukeed/svelte-preprocess-esbuild/workflows/CI/badge.svg)](https://github.com/lukeed/svelte-preprocess-esbuild/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/svelte-preprocess-esbuild)](https://codecov.io/gh/lukeed/svelte-preprocess-esbuild)\n\n\u003e A Svelte Preprocessor to compile TypeScript via [`esbuild`](https://github.com/evanw/esbuild)!\n\n\n## Install\n\n```\n$ npm install svelte-preprocess-esbuild esbuild --save-dev\n```\n\n\u003e **Note:** `esbuild` is a peer dependency!\n\n\n## Usage\n\nYou can use `svelte-preprocess-esbuild` alongside `svelte-preprocess`!\n\n***Example:*** `rollup.config.js`\n\nAn example `rollup.config.js`, that uses this plugin alongside [`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess).\n\n\u003e **Important:** When using `svelte-preprocess` (autopreprocessor), you must pass `false` to its `typescript` option. Otherwise, your TypeScript `\u003cscript\u003e`s will be compiled twice!\n\nPlease note that this is _not_ a complete Rollup configuration! \u003cbr\u003eRefer to [`rollup-plugin-svelte`](https://github.com/sveltejs/rollup-plugin-svelte) for more documentation.\n\n```js\n// rollup.config.js\nimport svelte from 'rollup-plugin-svelte';\nimport { typescript } from 'svelte-preprocess-esbuild';\nimport preprocess from 'svelte-preprocess';\n\nexport default {\n  // ...\n  plugins: [\n    // ...\n    svelte({\n      preprocess: [\n        typescript({\n          target: 'es2020',\n          define: {\n            'process.browser': 'true'\n          }\n        }),\n        // avoid double compile\n        preprocess({ typescript: false }),\n      ],\n      compilerOptions: {\n        // ...\n      }\n    })\n  ]\n}\n```\n\n***Example:*** `svelte.config.js`\n\n```js\n// svelte.config.js\nconst { typescript } = require('svelte-preprocess-esbuild');\nconst preprocess = require('svelte-preprocess');\n\nmodule.exports = {\n  preprocess: [\n    typescript({\n      // ...\n    }),\n    preprocess({\n      // avoid double\n      typescript: false\n    })\n  ],\n  compilerOptions: {\n    //\n  }\n}\n```\n\n## API\n\n### typescript(options?)\nReturns: `PreprocessorGroup`\n\nInvoke `esbuild` on all `\u003cscript\u003e` tags within your template that match any of the following:\n\n* a `lang=\"ts\"` attribute\n* a `lang=\"typescript\"` attribute\n* a `type=\"application/typescript\"` attribute\n* a `type=\"text/typescript\"` attribute\n* a `type=\"application/ts\"` attribute\n* a `type=\"text/ts\"` attribute\n* a non-external `src=\"\"` attribute that ends with `.ts` extension\n\nAdditionally, whenever `options.define` is given a value, **all** `\u003cscript\u003e` tags will be subject to [replacements](https://esbuild.github.io/api/#define), _including non-TypeScript contents!_\n\n#### options\nType: `Object`\u003cbr\u003e\nRequired: `false`\n\nA limited subset of [`esbuild.TransformOptions`](https://github.com/evanw/esbuild/blob/master/lib/types.ts#L126) is supported. These values are forced (for compatbility and/or reliability): `minify`, `loader`, `format`, and `errorLimit`.\n\nPlease see the exported [`Options` interface](https://github.com/lukeed/svelte-preprocess-esbuild/blob/master/src/index.ts#L17) for the full detail.\n\nBelow is the _only_ option that this plugin adds:\n\n#### options.tsconfig\nType: `string`\u003cbr\u003e\nDefault: `tsconfig.json`\n\nLoad a TypeScript configuration file. When found, is passed to `esbuild` as its `tsconfigRaw` option.\n\nWhen a value is given, an error will be thrown if the file cannot be found and/or parsed correctly.\n\nBy default, attempts to autoload `tsconfig.json`, but _will not_ throw if it's missing.\n\n\n### replace(dict)\nReturns: `PreprocessorGroup`\n\nInvoke `esbuild` on all non-TypeScript `\u003cscript\u003e`s, applying any static [string replacements](https://esbuild.github.io/api/#define).\n\n\u003e **Note:** This preprocessor will **ignore** TypeScript contents! \u003cbr\u003eIf you are using any TypeScript at all, you should be using the [`typescript` preprocessor](#typescriptoptions) with `options.define` instead.\n\n#### dict\nType: `Object`\n\nYour dictionary of key-value replacement pairs, where keys are replaced by their values.\n\n\u003e **Important:** All values ***must*** be stringified!\n\n```js\n// rollup.config.js\nimport svelte from 'rollup-plugin-svelte';\nimport { replace } from 'svelte-preprocess-esbuild';\n\nexport default {\n  // ...\n  plugins: [\n    // ...\n    svelte({\n      preprocess: [\n        replace({\n          'process.browser': JSON.stringify(true),\n          'process.env.BASEURL': JSON.stringify('https://foobar.com/'),\n        })\n      ]\n    })\n  ]\n}\n```\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fsvelte-preprocess-esbuild","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fsvelte-preprocess-esbuild","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fsvelte-preprocess-esbuild/lists"}