Let the vue project support glsl syntax

If you want your Vue project to support GLSL (OpenGL Shading Language) syntax, you need to use a special loader to enable Webpack to load and parse GLSL files. This can generally be achieved by the following steps:

  1. Install webpack-glsl-loader:
npm install webpack-glsl-loader--save-dev

If you use yarn as your package management tool, you can install it with the following command:

yarn add webpack-glsl-loader --dev
  1. Open your project's vue.config.jsfile and add a new rule to match GLSL files:
const {
    
     defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
    
    
transpileDependencies: true,
configureWebpack: (config) => {
    
    
  config.module.rules.push({
    
    
    test: /\.glsl$/,
    use: [
      {
    
    
        loader: "webpack-glsl-loader",
      },
    ],
  });
},
})

This rule tells webpack to use webpack-glsl-loader when it encounters a file with the suffix .glsl.

  1. In your Vue components, you can now directly reference .glslfiles using the import syntax, for example:
import vertexShader from './shaders/shader.vs.glsl'
import fragmentShader from './shaders/shader.fs.glsl'

glslify-loader processes the incoming files and returns a string that you can use directly in your WebGL program.

Note: Keep in mind that webpack needs to be restarted for the new loader configuration to take effect.

Guess you like

Origin blog.csdn.net/jieyucx/article/details/131922868