Skip to content

Commit 373c792

Browse files
author
Adam N
authored
Merge pull request #11 from Exomus/10-configuration-of-webpack-to-import-glsl-files-is-missing
fix: fix the configuration of Angular's webpack to accept glsl files in imports
2 parents 1fd2cea + 80f595e commit 373c792

File tree

8 files changed

+1135
-313
lines changed

8 files changed

+1135
-313
lines changed

angular.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
"prefix": "app",
1616
"architect": {
1717
"build": {
18-
"builder": "@angular-devkit/build-angular:browser",
18+
"builder": "@angular-builders/custom-webpack:browser",
1919
"options": {
20+
"customWebpackConfig": {
21+
"path": "./custom-webpack.config.js"
22+
},
2023
"outputPath": "dist/three-template",
2124
"index": "src/index.html",
2225
"main": "src/main.ts",
@@ -65,7 +68,7 @@
6568
"defaultConfiguration": "production"
6669
},
6770
"serve": {
68-
"builder": "@angular-devkit/build-angular:dev-server",
71+
"builder": "@angular-builders/custom-webpack:dev-server",
6972
"configurations": {
7073
"production": {
7174
"browserTarget": "three-template:build:production"

custom-webpack.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
module: {
3+
rules: [
4+
{
5+
test: /\.(glsl|vs|fs|vert|frag)$/,
6+
exclude: /node_modules/,
7+
use: [
8+
'raw-loader',
9+
'glslify-loader'
10+
]
11+
}
12+
]
13+
}
14+
}

package-lock.json

Lines changed: 1078 additions & 311 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
"@angular/platform-browser": "^14.0.0",
1919
"@angular/platform-browser-dynamic": "^14.0.0",
2020
"@angular/router": "^14.0.0",
21+
"glslify-loader": "^2.0.0",
2122
"lil-gui": "^0.16.1",
23+
"raw-loader": "^4.0.2",
2224
"rxjs": "~7.5.0",
2325
"three": "^0.141.0",
2426
"tslib": "^2.3.0",
2527
"zone.js": "~0.11.4"
2628
},
2729
"devDependencies": {
30+
"@angular-builders/custom-webpack": "^14.0.0",
2831
"@angular-devkit/build-angular": "^14.0.3",
2932
"@angular/cli": "~14.0.3",
3033
"@angular/compiler-cli": "^14.0.0",

src/shaders/example/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# GLSL Files
2+
3+
Some IDE will not recognize the import so you will need either one of the two following solutions.
4+
5+
## First method
6+
7+
You need to add `//@ts-ignore` above the imports of the GLSL files.
8+
9+
For example :
10+
11+
```typescript
12+
//@ts-ignore
13+
import vertexShader from 'src/shaders/example/vertex.glsl'
14+
```
15+
16+
## Second method
17+
18+
You add a file `glsl.d.ts` in the shader folder with inside:
19+
20+
```typescript
21+
declare module '*.glsl' {
22+
const value: string
23+
export default value
24+
}
25+
```

src/shaders/example/fragment.glsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void main() {
2+
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
3+
}

src/shaders/example/glsl.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.glsl' {
2+
const value: string
3+
export default value
4+
}

src/shaders/example/vertex.glsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void main() {
2+
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
3+
}

0 commit comments

Comments
 (0)