Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avensia-oss/ts-transform-export-const-folding
A TypeScript custom transform that removes and inlines imported constants
https://github.com/avensia-oss/ts-transform-export-const-folding
Last synced: about 2 months ago
JSON representation
A TypeScript custom transform that removes and inlines imported constants
- Host: GitHub
- URL: https://github.com/avensia-oss/ts-transform-export-const-folding
- Owner: avensia-oss
- License: mit
- Created: 2018-12-27T13:03:51.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-30T12:48:21.000Z (about 6 years ago)
- Last Synced: 2024-11-17T02:07:41.649Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 77.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-typescript-ecosystem - ts-transform-export-const-folding - This is a TypeScript custom transform that removes imported constants by inlining them. (Transformers / Optimization)
README
# ts-transform-export-const-folding
A 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:
```
// file1.ts
export const x = 'xxx';// file2.ts
import { x } from './file1';
let y = x;
```With this transform the above gets transformed into:
```
// file1.ts
export const x = 'xxx';// file2.ts
const x = 'xxx';
let y = x;
```What's the point of doing that? It removes the dependency between these modules, which means that they don't have to be bundled together.
# Installation
```
yarn add @avensia-oss/ts-transform-export-const-folding
```## Usage with webpack
Unfortunately 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:
https://github.com/TypeStrong/ts-loader#getcustomtransformers-----before-transformerfactory-after-transformerfactory--The 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:
```
const exportConstFoldingTransform = require('@avensia-oss/ts-transform-export-const-folding');return {
...
options: {
getCustomTransformers: (program) => ({
before: [exportConstFoldingTransform(program)]
})
}
...
};
```