Browse Source

replaced absolute paths to resources with relative

this allows the release build files in 'dist' to be copied over into
a static folder for the indy.io hugo site
Inderjit Gill 6 months ago
parent
commit
1f1fd854f9
4 changed files with 20 additions and 16 deletions
  1. 3
    2
      package.json
  2. 9
    6
      serve.go
  3. 7
    7
      web/js/Audio.js
  4. 1
    1
      web/js/index.js

+ 3
- 2
package.json View File

@@ -4,13 +4,14 @@
4 4
     "serve:release": "serve",
5 5
     "build:dev": "webpack --mode=development --progress",
6 6
     "build:dev:wasm": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_tetris.wasm --out-dir web",
7
-    "build:release": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/wasm_tetris.wasm --out-dir web && webpack --mode=production --progress && cp index.html dist/index.html",
7
+    "build:release": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/wasm_tetris.wasm --out-dir web && webpack --mode=production --progress && cp index.html dist/index.html && mkdirp dist/web && cp -r web/img dist/web/img && cp -r web/sfx dist/web/sfx",
8 8
     "build:server": "go build serve.go"
9 9
   },
10 10
   "devDependencies": {
11 11
     "webpack": "4.16.1",
12 12
     "webpack-cli": "3.1.0",
13
-    "webpack-dev-server": "3.1.4"
13
+    "webpack-dev-server": "3.1.4",
14
+    "mkdirp": "0.5.1"
14 15
   },
15 16
   "dependencies": {
16 17
     "howler": "2.0.14"

+ 9
- 6
serve.go View File

@@ -7,8 +7,14 @@ import (
7 7
 )
8 8
 
9 9
 /*
10
-serve web file from: /web (for images used as textures)
11
-serve everything else from: /dist (generated with npm run build:prod)
10
+build this file once:
11
+  $ go build serve.go
12
+
13
+build the release version with:
14
+  $ npm run build:release
15
+
16
+serve everything from /dist with:
17
+  $ ./serve
12 18
 */
13 19
 
14 20
 var wasmFile = regexp.MustCompile("\\.wasm$")
@@ -27,10 +33,7 @@ func maxAgeHandler(seconds int, h http.Handler) http.Handler {
27 33
 }
28 34
 
29 35
 func main() {
30
-	fs := http.FileServer(http.Dir("web"))
31
-	http.Handle("/web/", http.StripPrefix("/web/", fs))
32
-
33
-	fs = http.FileServer(http.Dir("dist"))
36
+	fs := http.FileServer(http.Dir("dist"))
34 37
 	http.Handle("/", maxAgeHandler(0, fs))
35 38
 
36 39
 	fmt.Printf("Serving localhost:3000\n")

+ 7
- 7
web/js/Audio.js View File

@@ -3,25 +3,25 @@ import { Howl, Howler } from "howler";
3 3
 export class Audio {
4 4
   constructor(config) {
5 5
     this.game_over = new Howl({
6
-      src: ['/web/sfx/negative1.mp3']
6
+      src: ['web/sfx/negative1.mp3']
7 7
     });
8 8
     this.line1 = new Howl({
9
-      src: ['/web/sfx/fanfare1.mp3']
9
+      src: ['web/sfx/fanfare1.mp3']
10 10
     });
11 11
     this.line2 = new Howl({
12
-      src: ['/web/sfx/fanfare1.mp3']
12
+      src: ['web/sfx/fanfare1.mp3']
13 13
     });
14 14
     this.line3 = new Howl({
15
-      src: ['/web/sfx/fanfare2.mp3']
15
+      src: ['web/sfx/fanfare2.mp3']
16 16
     });
17 17
     this.line4 = new Howl({
18
-      src: ['/web/sfx/fanfare3.mp3']
18
+      src: ['web/sfx/fanfare3.mp3']
19 19
     });
20 20
     this.pause_in = new Howl({
21
-      src: ['/web/sfx/pause2_in.mp3']
21
+      src: ['web/sfx/pause2_in.mp3']
22 22
     });
23 23
     this.pause_out = new Howl({
24
-      src: ['/web/sfx/pause2_out.mp3']
24
+      src: ['web/sfx/pause2_out.mp3']
25 25
     });
26 26
   }
27 27
 

+ 1
- 1
web/js/index.js View File

@@ -8,7 +8,7 @@ let gState = {
8 8
 
9 9
   config: new Config(),
10 10
 
11
-  tileset: '/web/img/tileset.png',
11
+  tileset: 'web/img/tileset.png',
12 12
 
13 13
   bridge: undefined,
14 14
   animationId: undefined,