question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[esbuild-plugin-meta-url] has no effect

See original GitHub issue

I recently started a project which tries to implement a map renderer in Rust. I’m currently evaluating which bundler is the best for the task as I require two features:

  • Inlining webworkers (or any module)
  • Resolving/Handling import.meta.url in CJS and ESM modules, especially for .wasm files.

I tried the plugin @chialab/esbuild-plugin-meta-url to solve the second goal, but esbuild is not copying assets to the output directory.

Config:

build.mjs

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

await esbuild.build({
    entryPoints: ['src/index.ts'],
    bundle: true,
    format: "esm",
    platform: "browser",
    outdir: "dist/esbuild/",
    plugins: [
        metaUrlPlugin(),
    ],
});

Is there more configuration needed?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
edoardocavazzacommented, May 2, 2022

Hello @maxammann. We have released a new version of the plugin (0.15.17). As you suggested, we tried to closely match the standard URL behavior, so we started to prefer local imports over modules resolution. We still support it for backward compatibility, but now it raises a warning. Thank you!

0reactions
maxammanncommented, Apr 28, 2022

I kind of agree that resolving modules could be handy for users. I would put that under a feature flag though as it does not conform to the default behavior.

In plain ES6 new URL("test.js", import.meta.url), called from https://example.com/main.js will resolve to: https://example.com/test.js

That means by definition resolving a file though URL + import.meta.url is relative. When transforming such a URL construct we should keep the relativity.

I tried the current implementation against the generated code by wasm_bindgen which expects it to be foremost relative.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can add support for __dirname and __filename? #859 - GitHub
meta.url to get at the path of the final bundle. Using a plugin gives the user control instead of having esbuild pick a...
Read more >
Plugins - esbuild
Plugins. The plugin API allows you to inject code into various parts of the build process. Unlike the rest of the API, it's...
Read more >
@chialab/esbuild-plugin-meta-url - npm
A file loader plugin for esbuild for constructed URLs using import metadata.. Latest version: 0.17.2, last published: 2 months ago.
Read more >
Changelog - esbuild - Breword 文档集合
This has the same effect as if you passed --target=es2021 to esbuild. ... achieve in an esbuild plugin because there was no way...
Read more >
Why vite.js doesn't work when I use npm run dev
This was caused by esbuild#2177 (on which Vite depends), which was just recently reverted in esbuild version 0.14.36. This issue should no ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found