Skip to content

Commit acd536b

Browse files
committed
call yo webgame
1 parent 3961750 commit acd536b

File tree

4 files changed

+2676
-1
lines changed

4 files changed

+2676
-1
lines changed

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
1-
# create-webgame
21
Generate a web game project.
2+
3+
To create a new web game project, all you need is npm:
4+
5+
```
6+
npm init webgame
7+
```
8+
9+
## Loading all types of files
10+
11+
webpack's [loader][wp-load] system is used to import files into your game. Your game will come with loaders for a few filetypes by default, such as images, fonts, and CSS.
12+
13+
If you need to load other types of files during the build, see [awesome-webpack][awesome-webpack] for a huge list of loaders of many filetypes.
14+
15+
To demonstrate how to add one of these loaders to your project, let's take `raw-loader` for example. It allows you to import any file as a String. Let's add it to your project.
16+
17+
```
18+
npm install raw-loader --save-dev
19+
```
20+
21+
Then open up `webpack.config.js` and add this object to the `rules` array. You'll see several other loaders already in the array, simply add this one to the end of the array.
22+
23+
```js
24+
{
25+
test: /\.txt$/i,
26+
use: 'raw-loader',
27+
},
28+
```
29+
30+
TODO: test these instructions
31+
32+
33+
## Publishing your game to NPM
34+
35+
If you wish to publish your game to NPM, remove the `private` flag from `package.json` and follow a blog post like [this one][first-npm] which steps through how to publish a package to NPM.
36+
37+
## When I save changes, `watch` doesn't recompile
38+
39+
This is usually due to editor configuration. Please see [webpack's suggestions][watch-tips] for how to disable "safe write" in your editor's configuration.
40+
41+
## Hot Module Reloading
42+
43+
TODO: write some docs on how to use HMR. An example in three.js of using HMR for live-refreshing shaders and textures would be excellent.
44+
45+
Under the tight pressure of a game jam, the extra work of setting up HMR probably isn't worth it, *unless* you know you're going to put a lot of work into a single shader, or texture. In that case, being able to save the shader or texture and have it show up immediately in the game is worth the up-front cost of setting up HMR.
46+
47+
## Lazy loading
48+
49+
If your game has some code, or some assets, that you don't need to load right away, you can lazy-load it as follows. This can be a nice optimization to get your main menu up as fast as possible, while other assets download in the background.
50+
51+
TODO: test and expand on these steps ( https://webpack.js.org/guides/code-splitting/#dynamic-imports )
52+
53+
1. To begin lazy loading the asset: `const lazyLoadedAsset = require("promise?global!./a-lazy-asset.js");`
54+
2. When the time comes that you really need the asset to be ready: `await lazyLoadedAsset;`
55+
56+
This feature is powered by webpack's [promise-loader][promise-loader].
57+
58+
## index.js
59+
60+
It's recommended that you leave the `index.js` file untouched, and implement your game within `game.js`. The purpose of `index.js` is to set up a few things before your game starts, such as a [Promise polyfill][es6-promise] and [browser feature detections][modernizr].
61+
62+
[es6-promise]: https://github.com/stefanpenner/es6-promise
63+
[watch-tips]: https://webpack.js.org/guides/development/#adjusting-your-text-editor
64+
[first-npm]: https://eladnava.com/publishing-your-first-package-to-npm/
65+
[wp-load]: https://webpack.js.org/concepts/loaders/
66+
[awesome-webpack]: https://github.com/webpack-contrib/awesome-webpack#loaders
67+
[promise-loader]: https://github.com/gaearon/promise-loader
68+
[modernizr]: https://modernizr.com/

create-webgame.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
yo --no-insight --no-update-notifier webgame

0 commit comments

Comments
 (0)