Maybe almost the most minimal clicker game ever - produce as many units as you can!
-
What: The purpose of this project is to experiment with a Web Worker in a vue-cli project (with TypeScript).
-
How: See
Engine.ts
, which acts as a proxy to the Web Workerworker.js
. The application can call methods ofEngine.ts
to post commands to the worker. The worker posts state updates toEngine.ts
, which updates application State. -
Why: The Web Worker operates in an independent thread from the application's JavaScript thread. The worker can perform computations without degrading the app's responsiveness.
Granted, this is a bit over-engineered for this example...
yarn install
: set up projectyarn serve
: serve on localhost with hot-reloadingyarn build
: build production distribution
Aside from standard vue-cli project, added the following for Web Worker support:
yarn add --dev worker-loader
I tried several configurations in vue.config.js
to allow *.worker.js
files to be loaded by worker-loader
during the webpack process. None of this worked. The answer was to simply load workers explicitly:
import Worker from "worker-loader!./worker.js"
git checkout develop
- Update
package.json
with versionX.Y.Z
- For GitHub Pages hosting:
- Run
yarn build
to producedist
- Remove old
docs
& movedist
todocs
- Remove all
*.map
sourcemaps withindocs
(unneeded in repo) - Run
http-server
indocs
to see if distribution works
- Run
git commit -am "vX.Y.Z"
git checkout master && git merge develop && git tag X.Y.Z
# nov
git push --all && git push --tags
git checkout develop
# back to work
GitHub Pages is hosting
/docs
offmaster
branch.
MIT License © Nathaniel Baughman
Share and enjoy :)