-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate static asset types to separate global package (#20433)
* feat(typings): create separate global declaration for static assets * feat(tools): use static-assets instead of custom-global global typings * Update typings/static-assets/README.md Co-authored-by: Peter Varholak <peter.varholak@gmail.com>
- Loading branch information
1 parent
f28a39a
commit bdeb8ff
Showing
6 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# static-assets | ||
|
||
Enables importing various static assets to JS/TS modules (which is invalid ECMA syntax enabled by various tools like webpack etc). | ||
|
||
This definition list is maintained manually and should be extended as needed. | ||
|
||
## Usage | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
"types": ["static-assets"] | ||
} | ||
} | ||
``` | ||
|
||
Now you can import images and others: | ||
|
||
```ts | ||
// @ExpectType string | ||
import myImgSrc from './hello-world.png` | ||
|
||
``` | ||
|
||
## Adding new asset types | ||
|
||
Add new asset types extension as needed. | ||
|
||
**Example:** | ||
|
||
```ts | ||
// Adding .avif image type support | ||
// ↓↓↓ | ||
declare module '*.avif' { | ||
const src: string; | ||
export default src; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Global ambient declaration of various non javascript assets being imported into JS/TS | ||
*/ | ||
|
||
declare module '*.svg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.gif' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpeg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.png' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.md' { | ||
const src: string; | ||
export default src; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"isolatedModules": true, | ||
"allowSyntheticDefaultImports": true, | ||
"skipLibCheck": false, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"types": ["node"] | ||
"types": ["node"], | ||
"typeRoots": ["node_modules/@types"] | ||
}, | ||
"include": ["**/*.d.ts"] | ||
} |