Esbuild Plugin Meta Url • A file loader plugin for esbuild for constructed URLs using import metadata.
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;
$ npm i @chialab/esbuild-plugin-meta-url -D
$ yarn add @chialab/esbuild-plugin-meta-url -D
import esbuild from 'esbuild';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';
await esbuild.build({
plugins: [
metaUrlPlugin(),
],
});
Esbuild Plugin Meta Url is released under the MIT license.