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

Undocumented raw-loader bug #24

Open
tom-leamon opened this issue Aug 17, 2023 · 0 comments
Open

Undocumented raw-loader bug #24

tom-leamon opened this issue Aug 17, 2023 · 0 comments

Comments

@tom-leamon
Copy link

I noticed what appears to be a bug when using this syntax:

import vertexShade from 'raw-loader!glslify-loader!./VertexShader.vert'
console.log(vertexShader)

would print

#define GLSLIFY 1
export default "#define GLSLIFY 1\nvarying vec2 vUv;\nvoid main() {\n  vUv = uv;\n  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";

Notice that it includes #define GLSLIFY 1 twice, and export default which makes it invalid GLSL. This would cause the shader compilation to fail.

Here is my webpack config:

rules: [
  {
    test: /\.(glsl|vs|fs|vert|frag)$/,
    exclude: /node_modules/,
    use: [
      'raw-loader',
      'glslify-loader'
    ]
  },
]

The Solution

I came across this in the documentation for raw-loader:

Beware, if you already define loader(s) for extension(s) in webpack.config.js you should use:

import css from '!!raw-loader!./file.txt'; // Adding `!!` to a request will disable all loaders specified in the configuration

When I added it to my code, it worked properly.

import vertexShader from '!!raw-loader!glslify-loader!./VertexShader.vert'
console.log(vertexShader)

now prints:

#define GLSLIFY 1
varying vec2 vUv;
void main() {
  vUv = uv;
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}

Now the shader compiles successfully. Not sure if this was an issue in my configuration somehow, and I'm not sure what to title this issue, but hope it helps someone.

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

1 participant