Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/longlho/ts-transform-img
Allow `import * as img from 'foo.png'` in TS
https://github.com/longlho/ts-transform-img
Last synced: about 1 month ago
JSON representation
Allow `import * as img from 'foo.png'` in TS
- Host: GitHub
- URL: https://github.com/longlho/ts-transform-img
- Owner: longlho
- License: mit
- Created: 2017-04-29T20:28:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-16T10:01:45.000Z (almost 2 years ago)
- Last Synced: 2024-10-20T17:52:40.121Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 269 KB
- Stars: 24
- Watchers: 3
- Forks: 2
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-typescript-ecosystem - ts-transform-img - Allow `import * as img from 'foo.png'` in TS (Transformers / General transformers)
README
# ts-transform-img
This is a TypeScript AST Transformer that allows you to write `import * as img from 'foo.png'`. Depending on file size, the img with be base64-inlined in the source or aggregated via `onImgExtracted`.
## Usage
First of all, you need some level of familiarity with the [TypeScript Compiler API](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API).`compile.ts` & tests should have examples of how this works. The available options are:
### `threshold?: number`
Threshold of img size that will be inlined, default to 10K### `interpolateName?: InterpolateNameFn | string`
Function to generate ID for the img asset### `onImgExtracted(id: string, filePath: string): void`
Function that gets triggered every time we found an asset