Skip to content

Latest commit

 

History

History
 
 

esbuild-plugin-meta-url

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

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 metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';

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

License

Esbuild Plugin Meta Url is released under the MIT license.