Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/esmfile/esbuild-plugin-esmfile

Import *.file.ts/*.file.js modules to build files using the file loader...For example, importing rocket-launch.svg.file.ts builds rocket-launch.svg in the build output directory during build time.
https://github.com/esmfile/esbuild-plugin-esmfile

Last synced: 3 months ago
JSON representation

Import *.file.ts/*.file.js modules to build files using the file loader...For example, importing rocket-launch.svg.file.ts builds rocket-launch.svg in the build output directory during build time.

Awesome Lists containing this project

README

        

[//]: @formatter:off
# esmfile

Import *.file.ts/*.file.js modules to build files using the file loader...For example, importing rocket-launch.svg.file.ts builds rocket-launch.svg in the build output directory during build time.

## install

```
npm i -D esbuild-plugin-esmfile
```

## usage

Build file

```ts
import { build } from 'esbuild'
import esmfile from 'esbuild-plugin-esmfile'
await build({
entryPoints: [/* source code entry point */],
plugins: [esmfile()]
})
```

Component file

```ts
import rocket_launch_svg from './rocket-launch.svg.file.js?stroke=green'
// rocket_launch_svg is the path to the rocket-launch-[hash].svg
// file in the esbuild output directory.
// The stroke of the icon is green.
export function html_() {
return `






`.trim()
}
```

rocket-launch.svg.file.ts
```ts
export default ()=>{
const url = new URL(import.meta.url)
const stroke = url.searchParams.get('stroke') ?? 'currentColor'
// language=svg
return (
''
)
}
```
[//]: @formatter:on