├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── assets │ └── phaser-planet-web.png ├── index.css ├── index.html ├── index.ts └── scenes │ └── boot.scene.ts ├── tsconfig.json ├── typings └── files │ └── index.d.ts ├── webpack.build.ts └── webpack.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.log 3 | src/assets/@raw/*/ 4 | dist/ 5 | ideas 6 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Eirik Slinning Korsnes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Phaser 3 / TypeScript / Webpack 2 | 3 | A simple, accessible boilerplate project for Phaser 3 using TypeScript and Webpack. 4 | 5 | ## Run 6 | 7 | `npm install` 8 | 9 | `npm start` 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phaser3-typescript-webpack", 3 | "version": "1.0.0", 4 | "main": "src/index.ts", 5 | "license": "MIT", 6 | "scripts": { 7 | "start": "npm run dev", 8 | "build": "webpack --mode production --config webpack.build.ts", 9 | "dev": "webpack-dev-server --mode development --config webpack.config.ts", 10 | "preview": "npx http-server dist" 11 | }, 12 | "dependencies": { 13 | "phaser": "3.80.0" 14 | }, 15 | "devDependencies": { 16 | "@types/node": "^20.11.19", 17 | "css-loader": "^6.10.0", 18 | "html-webpack-plugin": "^5.6.0", 19 | "mini-css-extract-plugin": "^2.8.0", 20 | "terser-webpack-plugin": "^5.3.10", 21 | "ts-loader": "^9.5.1", 22 | "ts-node": "^10.9.2", 23 | "tsconfig-paths-webpack-plugin": "^4.1.0", 24 | "tslint": "^5.9.1", 25 | "typescript": "^5.3.3", 26 | "webpack": "^5.90.3", 27 | "webpack-cli": "^5.1.4", 28 | "webpack-dev-server": "^5.0.2" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/assets/phaser-planet-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ampled/phaser3-typescript-webpack/d51e53233552bd3ec56b01f0ec3f300ae6c3a6a9/src/assets/phaser-planet-web.png -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | /* height: 100%; */ 4 | margin: 0; 5 | padding: 0; 6 | width: 100%; 7 | background-color: black; 8 | color: white; 9 | } 10 | 11 | * { 12 | box-sizing: border-box; 13 | } 14 | 15 | a { 16 | color: white; 17 | font-size: 1.5em; 18 | } 19 | 20 | /* #gamecontainer { 21 | max-height: 960px; 22 | } */ 23 | 24 | #game { 25 | /* margin-left: auto; 26 | margin-right: auto; 27 | max-width: 1600px; 28 | background-color: #666; 29 | width: 100%; 30 | aspect-ratio: 800 / 480; 31 | border-radius: 16px; */ 32 | /* text-align: center; */ 33 | } 34 | 35 | #info { 36 | margin-left: auto; 37 | margin-right: auto; 38 | width: 400px; 39 | } 40 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Phaser 3 / TypeScript / Webpack 6 | 7 | 8 | 9 |
10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import 'phaser'; 2 | 3 | import './index.css'; 4 | 5 | import { BootScene } from 'scenes/boot.scene'; 6 | 7 | const config: Phaser.Types.Core.GameConfig = { 8 | type: Phaser.CANVAS, 9 | backgroundColor: '#ADD8E6', 10 | parent: 'game', 11 | width: 800, 12 | height: 480, 13 | zoom: 1, 14 | pixelArt: true, 15 | scale: { 16 | mode: Phaser.Scale.FIT, 17 | parent: 'game', 18 | autoCenter: Phaser.Scale.CENTER_BOTH, 19 | min: { 20 | width: 800, 21 | height: 480, 22 | }, 23 | max: { 24 | width: 800 * 2, 25 | height: 480 * 2, 26 | }, 27 | }, 28 | scene: [BootScene], 29 | }; 30 | 31 | new Phaser.Game(config); 32 | -------------------------------------------------------------------------------- /src/scenes/boot.scene.ts: -------------------------------------------------------------------------------- 1 | import phaserLogo from '../assets/phaser-planet-web.png'; 2 | 3 | export class BootScene extends Phaser.Scene { 4 | constructor() { 5 | super({ key: 'BootScene' }); 6 | } 7 | 8 | preload() { 9 | this.load.image('phaser-logo', phaserLogo); 10 | } 11 | 12 | create() { 13 | this.add.tween({ 14 | targets: this.add.image(400, 240, 'phaser-logo'), 15 | scaleX: 2, 16 | scaleY: 2, 17 | yoyo: true, 18 | repeat: -1, 19 | duration: 2000, 20 | ease: Phaser.Math.Easing.Sine.InOut, 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "src", 4 | "target": "es2015", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "strict": false, 8 | "noImplicitAny": false, 9 | "strictPropertyInitialization": false, 10 | "sourceMap": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "resolveJsonModule": false, 14 | "typeRoots": ["typings"] 15 | }, 16 | "ts-node": { 17 | "compilerOptions": { 18 | "module": "CommonJS", 19 | "allowSyntheticDefaultImports": true 20 | } 21 | }, 22 | "exclude": ["node_modules", "assets"] 23 | } 24 | -------------------------------------------------------------------------------- /typings/files/index.d.ts: -------------------------------------------------------------------------------- 1 | /*** 2 | * Wildcard module-declarations so typescript don't complain when importing files other than .ts or .js with file-loader 3 | */ 4 | 5 | declare module '*.png' { 6 | const content: string; 7 | export = content; 8 | } 9 | declare module '*.fnt' { 10 | const content: string; 11 | export = content; 12 | } 13 | declare module '*.json' { 14 | const content: string; 15 | export = content; 16 | } 17 | declare module '*.ogg' { 18 | const content: string; 19 | export = content; 20 | } 21 | declare module '*.mp3' { 22 | const content: string; 23 | export = content; 24 | } 25 | -------------------------------------------------------------------------------- /webpack.build.ts: -------------------------------------------------------------------------------- 1 | import { Configuration } from 'webpack'; 2 | import config from './webpack.config'; 3 | import TerserPlugin from 'terser-webpack-plugin'; 4 | 5 | const buildConfig: Configuration = { 6 | ...config, 7 | optimization: { minimize: true, minimizer: [new TerserPlugin()] }, 8 | }; 9 | 10 | export default buildConfig; 11 | -------------------------------------------------------------------------------- /webpack.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import HtmlWebPackPlugin from 'html-webpack-plugin'; 3 | import MiniCssExtractPlugin from 'mini-css-extract-plugin'; 4 | import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'; 5 | import type { Configuration } from 'webpack'; 6 | 7 | import webpack from 'webpack'; 8 | import path from 'path'; 9 | 10 | const config: Configuration = { 11 | devServer: { 12 | host: 'localhost', 13 | hot: true, 14 | static: [path.resolve(__dirname, 'src', 'assets')], 15 | }, 16 | entry: { 17 | main: path.resolve(__dirname, 'src/index.ts'), 18 | }, 19 | resolve: { 20 | extensions: ['.ts', '.js'], 21 | plugins: [new TsconfigPathsPlugin()], 22 | }, 23 | output: { 24 | assetModuleFilename: 'images/[hash][ext][query]', 25 | path: path.resolve(__dirname, 'dist'), 26 | }, 27 | optimization: { 28 | minimize: false, 29 | minimizer: [], 30 | }, 31 | plugins: [ 32 | new webpack.DefinePlugin({ 33 | WEBGL_RENDERER: true, 34 | CANVAS_RENDERER: true, 35 | USELOCALSTORAGE: true, 36 | 'typeof SHADER_REQUIRE': JSON.stringify(false), 37 | 'typeof CANVAS_RENDERER': JSON.stringify(true), 38 | 'typeof WEBGL_RENDERER': JSON.stringify(true), 39 | }), 40 | new HtmlWebPackPlugin({ 41 | template: './src/index.html', 42 | }), 43 | new MiniCssExtractPlugin(), 44 | ], 45 | module: { 46 | rules: [ 47 | { 48 | test: /\.ts$/, 49 | exclude: /\.tsx$/, 50 | use: [ 51 | { 52 | loader: 'ts-loader', 53 | options: { 54 | transpileOnly: true, 55 | }, 56 | }, 57 | ], 58 | }, 59 | { 60 | test: [/\.vert$/, /\.frag$/], 61 | type: 'asset/source', 62 | }, 63 | { 64 | test: [/\.(png|fnt|mp3|ogg)$/], 65 | type: 'asset/resource', 66 | generator: { 67 | filename: 'assets/[name].[hash][ext]', 68 | }, 69 | }, 70 | { 71 | test: /\.json$/, 72 | type: 'asset/resource', 73 | generator: { 74 | filename: '[name].[hash][ext]', 75 | }, 76 | }, 77 | { 78 | test: /\.css$/i, 79 | use: [MiniCssExtractPlugin.loader, 'css-loader'], 80 | }, 81 | ], 82 | }, 83 | }; 84 | 85 | export default config; 86 | --------------------------------------------------------------------------------