@chialab/esbuild-plugin-meta-url

A file loader plugin for esbuild for constructed URLs using import metadata.

Usage no npm install needed!

<script type="module">
  import chialabEsbuildPluginMetaUrl from 'https://cdn.skypack.dev/@chialab/esbuild-plugin-meta-url';
</script>

README

Esbuild Plugin Meta Url • A file loader plugin for esbuild for constructed URLs using import metadata.

NPM


How it works

Esbuild Plugin Meta Url looks for new URL('path/to/file.png', import.meta.url) in JavaScript and TypeScript files and instructs esbuild to copy referenced files. This is a standard version of the file loader.

// DONT ❌
import img from './logo.png';

// DO ✅
const img = new URL('./logo.png', import.meta.url).href;

Install

$ npm i @chialab/esbuild-plugin-meta-url -D
$ yarn add @chialab/esbuild-plugin-meta-url -D

Usage

import esbuild from 'esbuild';
import transfrom from '@chialab/esbuild-plugin-transform';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';

await esbuild.build({
    plugins: [
        transfrom([
            metaUrlPlugin(),
        ]),
    ],
});

License

Esbuild Plugin Meta Url is released under the MIT license.