{"id":13834720,"url":"https://github.com/avensia-oss/ts-transform-export-const-folding","last_synced_at":"2025-04-07T06:39:00.249Z","repository":{"id":57099923,"uuid":"163295469","full_name":"avensia-oss/ts-transform-export-const-folding","owner":"avensia-oss","description":"A TypeScript custom transform that removes and inlines imported constants","archived":false,"fork":false,"pushed_at":"2018-12-30T12:48:21.000Z","size":79,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-17T20:18:36.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/avensia-oss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-27T13:03:51.000Z","updated_at":"2022-06-08T14:34:14.000Z","dependencies_parsed_at":"2022-08-22T23:10:40.788Z","dependency_job_id":null,"html_url":"https://github.com/avensia-oss/ts-transform-export-const-folding","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avensia-oss%2Fts-transform-export-const-folding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avensia-oss%2Fts-transform-export-const-folding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avensia-oss%2Fts-transform-export-const-folding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avensia-oss%2Fts-transform-export-const-folding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avensia-oss","download_url":"https://codeload.github.com/avensia-oss/ts-transform-export-const-folding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608183,"owners_count":20965950,"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-04T14:00:51.431Z","updated_at":"2025-04-07T06:39:00.230Z","avatar_url":"https://github.com/avensia-oss.png","language":"TypeScript","funding_links":[],"categories":["Transformers"],"sub_categories":["Optimization"],"readme":"# ts-transform-export-const-folding\r\n\r\nA rather long name, but a descriptive one (hopefully) at least. This is a TypeScript custom transform that removes imported constants by inlining them. An example would be:\r\n\r\n```\r\n// file1.ts\r\nexport const x = 'xxx';\r\n\r\n// file2.ts\r\nimport { x } from './file1';\r\nlet y = x;\r\n```\r\n\r\nWith this transform the above gets transformed into:\r\n\r\n```\r\n// file1.ts\r\nexport const x = 'xxx';\r\n\r\n// file2.ts\r\nconst x = 'xxx';\r\nlet y = x;\r\n```\r\n\r\nWhat's the point of doing that? It removes the dependency between these modules, which means that they don't have to be bundled together.\r\n\r\n# Installation\r\n\r\n```\r\nyarn add @avensia-oss/ts-transform-export-const-folding\r\n```\r\n\r\n## Usage with webpack\r\n\r\nUnfortunately TypeScript doesn't let you specifiy custom transformers in `tsconfig.json`. If you're using `ts-loader` with webpack you can specify it like this:\r\nhttps://github.com/TypeStrong/ts-loader#getcustomtransformers-----before-transformerfactory-after-transformerfactory--\r\n\r\nThe default export of this module is a function which expects a `ts.Program` an returns a transformer function. Your config should look something like this:\r\n\r\n```\r\nconst exportConstFoldingTransform = require('@avensia-oss/ts-transform-export-const-folding');\r\n\r\nreturn {\r\n  ...\r\n  options: {\r\n    getCustomTransformers: (program) =\u003e ({\r\n      before: [exportConstFoldingTransform(program)]\r\n    })\r\n  }\r\n  ...\r\n};\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favensia-oss%2Fts-transform-export-const-folding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favensia-oss%2Fts-transform-export-const-folding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favensia-oss%2Fts-transform-export-const-folding/lists"}