Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicts with other loaders #77

Open
mayerraphael opened this issue Jul 8, 2023 · 1 comment
Open

Conflicts with other loaders #77

mayerraphael opened this issue Jul 8, 2023 · 1 comment

Comments

@mayerraphael
Copy link

mayerraphael commented Jul 8, 2023

Because of the automatically registered "file" specifier, this conflicts with any defined loaders that also use file.

For example following esbuild options:

{
    plugins: [...denoPlugins()],
    entryPoints: entryPoints,
    ...
    loader: {
      ".graphql": "file",
    },
  }

If i now import a graphql file like this:

import query from "./query.graphql";

The deno-loader plugin throws the following error:

 The module's source code could not be parsed: Expected ',', got ':'
 ~ [plugin deno-loader]

The plugin should not handle all file namespaces as TypeScript/JavaScript files.

@niedzielski
Copy link

I agree with your assessment. I was able to wrap the default loaders like text and dataurl to lock files to a new namespace and ordering the plugin before esbuild_deno_loader's plugins like:

const dataURILoader: esbuild.Plugin = {
  name: 'DataURILoader',
  setup(build) {
    build.onResolve({ filter: /\.svg$/ }, (args) => ({
      path: path.join(args.resolveDir, args.path),
      namespace: textLoader.name,
    }))

    build.onLoad(
      { filter: /\.svg$/, namespace: textLoader.name },
      async (args) => ({
        contents: await Deno.readTextFile(args.path),
        loader: 'dataurl',
      }),
    )
  },
}
const opts: esbuild.BuildOptions = {
  ...
  plugins: [
    dataURILoader,
    ...denoPlugins() as unknown as esbuild.Plugin[],
  ],
  ...
}

It's very clumsy but fortunately isolated to my build script.

The bigger issue to me is denoland/deno#15132 which has nothing to do with esbuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants