{"id":13791912,"url":"https://github.com/favware/esbuild-plugin-file-path-extensions","last_synced_at":"2025-07-13T19:31:28.213Z","repository":{"id":61555268,"uuid":"552456696","full_name":"favware/esbuild-plugin-file-path-extensions","owner":"favware","description":"An esbuild plugin to automatically insert file extensions in your built JavaScript files based on the specified target","archived":false,"fork":false,"pushed_at":"2024-04-14T08:42:38.000Z","size":6534,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-18T21:39:56.286Z","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/favware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":["favna"],"patreon":"favna","open_collective":null,"ko_fi":"favna","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://donate.favware.tech/paypal"}},"created_at":"2022-10-16T16:32:21.000Z","updated_at":"2024-04-21T03:03:27.983Z","dependencies_parsed_at":"2023-12-24T01:29:53.938Z","dependency_job_id":"6c4e5fc2-fec9-4273-bb79-28e20bf2edc4","html_url":"https://github.com/favware/esbuild-plugin-file-path-extensions","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"5eba092671ce80fb459cbb7caa05f8b56f611ba6"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":"sapphiredev/sapphire-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-file-path-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-file-path-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-file-path-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favware%2Fesbuild-plugin-file-path-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/favware","download_url":"https://codeload.github.com/favware/esbuild-plugin-file-path-extensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224986373,"owners_count":17402937,"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-03T22:01:05.725Z","updated_at":"2024-11-22T14:29:16.881Z","avatar_url":"https://github.com/favware.png","language":"TypeScript","funding_links":["https://github.com/sponsors/favna","https://patreon.com/favna","https://ko-fi.com/favna","https://donate.favware.tech/paypal","https://github.com/sponsors/Favna"],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# esbuild-plugin-file-path-extensions\n\n**An esbuild plugin to automatically insert file extensions in your built\nJavaScript files based on the specified target**\n\n[![GitHub](https://img.shields.io/github/license/favware/esbuild-plugin-file-path-extensions)](https://github.com/favware/esbuild-plugin-file-path-extensions/blob/main/LICENSE.md)\n[![npm](https://img.shields.io/npm/v/esbuild-plugin-file-path-extensions?color=crimson\u0026logo=npm\u0026style=flat-square)](https://www.npmjs.com/package/esbuild-plugin-file-path-extensions)\n\n\u003c/div\u003e\n\n**Table of Contents**\n\n- [esbuild-plugin-file-path-extensions](#esbuild-plugin-file-path-extensions)\n  - [Description](#description)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [With [`esbuild`][esbuild]](#with-esbuildesbuild)\n    - [With [`tsup`][tsup]](#with-tsuptsup)\n  - [Options](#options)\n  - [Buy us some doughnuts](#buy-us-some-doughnuts)\n  - [Contributors](#contributors)\n\n## Description\n\nIn order to properly and fully support packaging your code for both CJS and ESM\nwhen using esbuild you will want to ensure that all your imports and exports are\nusing their respective file extensions (i.e. `.js` for CJS and `.mjs` for ESM)\nto ensure that NodeJS can always load the appropriate files when they are within\nthe same folder. However, managing this manually is an absolute nightmare and\nannoyance to do in the source code. This plugin alleviates that issue by\nautomatically appending the file path extensions when building the code.\n\n## Installation\n\nYou can use the following command to install this package, or replace\n`npm install -D` with your package manager of choice.\n\n```sh\nnpm install -D esbuild-plugin-file-path-extensions\n```\n\n## Usage\n\n\u003e **Warning** When using this plugin you **_HAVE_** to set the `bundle` option\n\u003e to true for file paths to be resolved correctly. Do note however then when\n\u003e doing this your code will NOT bundle all into 1 file. An example of where this\n\u003e plugin is used and what the output will be after it is used can be found at\n\u003e [sapphiredev/framework][framework]\n\n\u003e **Note** If you import a file and append a file one of the file extensions\n\u003e `js`, `cjs`, `mjs`, `ts`, `cts`, or `mts` then this plugin will skip that\n\u003e import and use the originally provided extension. This is to ensure that no\n\u003e double file extensions are added.\n\n### With [`esbuild`][esbuild]\n\nAdd the plugin to your esbuild options, i.e.:\n\n```js\nconst esbuild = require('esbuild');\nconst { resolve } = require('path');\nconst {\n  esbuildPluginFilePathExtensions\n} = require('esbuild-plugin-file-path-extensions');\n\nawait esbuild.build({\n  format: 'cjs',\n  entryPoints: [resolve(__dirname, './src/index.ts')],\n  outdir: resolve(__dirname, './dist'),\n  bundle: true,\n  plugins: [esbuildPluginFilePathExtensions()]\n});\n```\n\n### With [`tsup`][tsup]\n\nAdd the plugin to your `tsup.config.ts`, i.e.:\n\n```js\nimport { defineConfig } from 'tsup';\nimport { resolve } from 'path';\nimport { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions';\n\nawait defineConfig({\n  format: ['cjs', 'esm'],\n  entry: ['src/**/*.ts'],\n  outDir: './dist',\n  bundle: true,\n  esbuildPlugins: [esbuildPluginFilePathExtensions()]\n});\n```\n\n[esbuild]: https://esbuild.github.io/\n[tsup]: https://tsup.egoist.dev\n\n## Options\n\nThe plugin accepts the following options:\n\n- `esm`: Boolean, whether the current build is for ESM or not. Defaults to\n  `build.initialOptions?.define?.TSUP_FORMAT === '\"esm\"'` in order to account\n  for the cross-target capabilities of `tsup`.\n\n- `cjsExtension`: The extension to apply for CJS code. Defaults to `js`. Make\n  sure to **NOT** start with a leading `.`.\n\n- `esmExtension`: The extension to apply for ESM code. Defaults to `mjs`. Make\n  sure to **NOT** start with a leading `.`.\n\n- `filter`: This is an advanced use-case option with which you can filter which\n  files esbuild should apply this plugin on\n\n- `namespace`: This is an advanced use-case option through which the\n  [esbuild namespace](https://esbuild.github.io/plugins/#namespaces) can be\n  configured\n\n## Buy us some doughnuts\n\nFavware projects are and always will be open source, even if we don't get\ndonations. That being said, we know there are amazing people who may still want\nto donate just to show their appreciation. Thank you very much in advance!\n\nWe accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships, and\nvarious cryptocurrencies. You can use the buttons below to donate through your\nmethod of choice.\n\n|   Donate With   |                      Address                      |\n| :-------------: | :-----------------------------------------------: |\n|      Ko-fi      |  [Click Here](https://donate.favware.tech/kofi)   |\n|     Patreon     | [Click Here](https://donate.favware.tech/patreon) |\n|     PayPal      | [Click Here](https://donate.favware.tech/paypal)  |\n| GitHub Sponsors |  [Click Here](https://github.com/sponsors/Favna)  |\n|     Bitcoin     |       `1E643TNif2MTh75rugepmXuq35Tck4TnE5`        |\n|    Ethereum     |   `0xF653F666903cd8739030D2721bF01095896F5D6E`    |\n|    LiteCoin     |       `LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6`        |\n\n## Contributors\n\nPlease make sure to read the [Contributing Guide][contributing] before making a\npull request.\n\nThank you to all the people who already contributed!\n\n\u003ca href=\"https://github.com/favware/esbuild-plugin-file-path-extensions/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=favware/esbuild-plugin-file-path-extensions\" /\u003e\n\u003c/a\u003e\n\n[contributing]: .github/CONTRIBUTING.md\n[framework]: https://github.com/sapphiredev/framework\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavware%2Fesbuild-plugin-file-path-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffavware%2Fesbuild-plugin-file-path-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavware%2Fesbuild-plugin-file-path-extensions/lists"}