UstymUkhman / vite-plugin-glsl

:spider_web: Import, inline (and compress) GLSL shader files :electric_plug:
https://www.npmjs.com/package/vite-plugin-glsl
MIT License
321 stars 21 forks source link

Recursion Detection Warning fires when there is no recursion. #11

Closed ryandurkoske closed 2 years ago

ryandurkoske commented 2 years ago

If you have two separate WebGL programs on you're site, and say programA.frag and programB.frag both include a utility function, the "Recursion detected" warning fires. Obviously, recursion would never be the first problem you would run into when trying to macro two separate shader programs together.

Checking to see if a file is included more than once is sufficient for this specific scenario, but it should be taken into account that their can be completely separate include trees.

Warning: 'programB.frag' was included multiple times. Please avoid multiple imports of the same chunk in order to avoid unwanted recursions. Last import found in file 'noise.glsl'.

Nothing breaks, but it is annoying for those that like a clean console window. Other than that, thanks for providing this tool! It works way better than any webpack solution I've used.

UstymUkhman commented 2 years ago

Hi @ryandurkoske , thanks for reporting this issue. Obviously I haven't consider multiple programs accessing the same shader chunk could cause a false recursion warning. This check seems to causing more problems that it's trying to solve. πŸ˜„

Anyway, I'll probably add a new config option when I get some more info related to issue #10 , it will look something like this:

import glsl from 'vite-plugin-glsl';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [glsl({ checkRecursiveImports: false })]
});

in order to prevent this check. What do you think, it might work for you? For now you can still use v0.1.2 since the only difference is this "recursive check", so everything else should work just the same.

P.S.: Thanks for using this plugin, I'm glad you've found it useful. Please consider giving a ⭐to this project if that's a case. Thanks!

UstymUkhman commented 2 years ago

@ryandurkoske Starting from version 0.2.0 you are now able to disable this check with the following option:

import glsl from 'vite-plugin-glsl';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [glsl({ warnDuplicatedImports: false })]
});

Hope that helps to keep your console window clean, 'cause I'm also a fan of that. 😁 Feel free to open a new issue if you notice some problem related (or not) to this check.

Cheers!