简体   繁体   English

GLSL 文件:“模块解析失败:意外令牌”

[英]GLSL File: "Module parse failed: Unexpected token"

I am building image transition with a custom shader and for this i need a fragment.glsl.我正在使用自定义着色器构建图像过渡,为此我需要一个 fragment.glsl。 But when importing this file into my .js, this error shows up:但是当将此文件导入我的 .js 时,会出现此错误:

Compiled with problems:

ERROR in ./src/shaders/fragment.glsl 1:13

Module parse failed: Unexpected token (1:13)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> void main () {
| 
| }

For a fast start i am using this webpack boilerplate: https://github.com/taniarascia/webpack-boilerplate为了快速开始,我正在使用这个 webpack 样板: https ://github.com/taniarascia/webpack-boilerplate

Because of my not existing experience in webpack and glsl files i dont know whats wrong.由于我在 webpack 和 glsl 文件方面没有经验,我不知道出了什么问题。 I am assuming, that the browser is not able to read the file.我假设浏览器无法读取该文件。 I tried a lot of stuff with webpack.config.js and modules like glfl-loader but looks like my browser got other plans.我用 webpack.config.js 和 glfl-loader 之类的模块尝试了很多东西,但看起来我的浏览器有其他计划。

After testing around i found the solution:经过四处测试,我找到了解决方案:

i had to edit this to the webpack.config.js我不得不将它编辑到webpack.config.js

// Shader // 着色器

{ test: /\.(glsl|vs|fs|vert|frag)$/,  type: 'asset/source',generator: { filename: 'assets/images/[hash][ext]' }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM