Skip to content

Instantly share code, notes, and snippets.

@Bjvanminnen
Last active January 8, 2023 15:52
Show Gist options
  • Save Bjvanminnen/595d9fef3b1320d1f94632f8c2d323ef to your computer and use it in GitHub Desktop.
Save Bjvanminnen/595d9fef3b1320d1f94632f8c2d323ef to your computer and use it in GitHub Desktop.
How to use glslify with create-react-app

Create your app

create-react-app my-app
cd my-app

Eject it, so that we can modify webpack config

npm run eject
y # when prompted

Install the necessary loaders

yarn add glslify-loader raw-loader

Edit config/webpack.config.dev.js. Add to module.rules in the oneOf section

{
  test: /\.(glsl|frag|vert)$/,
  use: [
    require.resolve('raw-loader'),
    require.resolve('glslify-loader'),
  ]
},

At this point you should be able to require your shader files by just doing

import myShader from './myShader.glsl'

Within your shader, you can import from other shaders

// in myShader.glsl

// import from node_modules
import noise from 'glsl-noise/simplex/2d'

// import from relative
import foo from './lib/foo.glsl';

In the later case, you'll also want to export from foo.glsl

#pragma glslify: export(foo)
@hydrosquall
Copy link

hydrosquall commented Apr 2, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment