lucacasonato / esbuild_deno_loader

Deno module resolution for `esbuild`
https://jsr.io/@luca/esbuild-deno-loader
MIT License
176 stars 46 forks source link

Quick question: Is there a way to ignore `.css` entry points? #134

Closed stephband closed 3 months ago

stephband commented 3 months ago

I just got this lovely set of plugins building my project, thank you. I was using ESbuild to bundle both JS and CSS – not together, but as separate entry points:

es.build({
    entryPoints: [
        './module.js', 
        './module.css'
    ],

    plugins: [...denoPlugins({
        configPath: workingdir + 'deno.json',
        lockPath:   workingdir + 'deno.lock'
    })]

    ...
}

Unfortunately denoPlugins() borks when fed CSS.

Expected a JavaScript or TypeScript module, but identified a Unknown module. ...

Is there a way to get it to ignore these entry points?

hesxenon commented 3 months ago

there "kinda" is:

    {
      name: "skip css",
      setup: (build) => {
        build.onResolve({ filter: /\.css$/, namespace: "file" }, (args) => {
          return {
            path: Path.resolve(args.resolveDir, args.path),
          };
        });
        build.onLoad({ filter: /\.css$/, namespace: "file" }, (args) => {
          const contents = Deno.readFileSync(args.path);
          return {
            contents: contents,
            loader: "css",
          };
        });
        build.onResolve({ filter: /.*/, namespace: "data" }, (args) => {
          return args.kind !== "url-token" ? undefined : { external: true };
        });
      },
    },
    ...denoPlugins({

so this basically handles css resolution and loading before one of the denoPlugins has a chance to handle that.

stephband commented 3 months ago

Of course, whack a handler in before denoPlugins(). I don't know why I didn't try that, I think I was influenced by this text in the README "In most cases, the denoResolverPlugin should be the first plugin in the plugin array".

Thank you, this solves my problem.

hesxenon commented 3 months ago

yeah, but the issue still exists, no?

On Wed, Aug 21, 2024, 20:29 stephband @.***> wrote:

Closed #134 https://github.com/lucacasonato/esbuild_deno_loader/issues/134 as completed.

— Reply to this email directly, view it on GitHub https://github.com/lucacasonato/esbuild_deno_loader/issues/134#event-13964783414, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOHZTT3JJ35EKCLJ4XK3PTZSTMA3AVCNFSM6AAAAABLZE35DKVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJTHE3DINZYGM2DCNA . You are receiving this because you commented.Message ID: @.*** .com>