├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── index.html ├── log.js ├── package-lock.json ├── package.json ├── public ├── assets │ ├── bg.png │ └── logo.png ├── favicon.png └── style.css ├── screenshot.png ├── src ├── game │ ├── main.js │ └── scenes │ │ ├── Boot.js │ │ ├── Game.js │ │ ├── GameOver.js │ │ ├── MainMenu.js │ │ └── Preloader.js └── main.js └── webpack ├── config.js └── config.prod.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/env", { 4 | "targets": { 5 | "browsers": [ 6 | ">0.25%", 7 | "not ie 11", 8 | "not op_mini all" 9 | ] 10 | }, 11 | "modules": false 12 | }] 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # System and IDE files 2 | Thumbs.db 3 | .DS_Store 4 | .idea 5 | *.suo 6 | *.sublime-project 7 | *.sublime-workspace 8 | *.vscode 9 | 10 | # Vendors 11 | node_modules/ 12 | 13 | # Build 14 | dist/ 15 | /npm-debug.log 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Phaser Studio Inc 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 Webpack Template 2 | 3 | This is a Phaser 3 project template that uses webpack for bundling. It supports hot-reloading for quick development workflow and includes scripts to generate production-ready builds. 4 | 5 | **[This Template is also available as a TypeScript version.](https://github.com/phaserjs/template-webpack-ts)** 6 | 7 | ### Versions 8 | 9 | This template has been updated for: 10 | 11 | - [Phaser 3.90.0](https://github.com/phaserjs/phaser) 12 | - [Webpack 5.99.6](https://github.com/webpack/webpack) 13 | 14 | ![screenshot](screenshot.png) 15 | 16 | ## Requirements 17 | 18 | [Node.js](https://nodejs.org) is required to install dependencies and run scripts via `npm`. 19 | 20 | ## Available Commands 21 | 22 | | Command | Description | 23 | |---------|-------------| 24 | | `npm install` | Install project dependencies | 25 | | `npm run dev` | Launch a development web server | 26 | | `npm run build` | Create a production build in the `dist` folder | 27 | | `npm run dev-nolog` | Launch a development web server without sending anonymous data (see "About log.js" below) | 28 | | `npm run build-nolog` | Create a production build in the `dist` folder without sending anonymous data (see "About log.js" below) | 29 | 30 | ## Writing Code 31 | 32 | After cloning the repo, run `npm install` from your project directory. Then, you can start the local development server by running `npm run dev`. 33 | 34 | The local development server runs on `http://localhost:8080` by default. Please see the webpack documentation if you wish to change this, or add SSL support. 35 | 36 | Once the server is running you can edit any of the files in the `src` folder. Webpack will automatically recompile your code and then reload the browser. 37 | 38 | ## Template Project Structure 39 | 40 | We have provided a default project structure to get you started. This is as follows: 41 | 42 | | Path | Description | 43 | |------------------------------|------------------------------------------------------------| 44 | | `public/index.html` | A basic HTML page to contain the game. | 45 | | `public/assets` | Game sprites, audio, etc. Served directly at runtime. | 46 | | `public/style.css` | Global layout styles. | 47 | | `src/main.js` | Application bootstrap. | 48 | | `src/game` | Folder containing the game code. | 49 | | `src/game/main.js` | Game entry point: configures and starts the game. | 50 | | `src/game/scenes` | Folder with all Phaser game scenes. | 51 | 52 | 53 | ## Handling Assets 54 | 55 | Webpack supports loading assets via JavaScript module `import` statements. 56 | 57 | This template provides support for both embedding assets and also loading them from a static folder. To embed an asset, you can import it at the top of the JavaScript file you are using it in: 58 | 59 | ```js 60 | import logoImg from './assets/logo.png' 61 | ``` 62 | 63 | To load static files such as audio files, videos, etc place them into the `public/assets` folder. Then you can use this path in the Loader calls within Phaser: 64 | 65 | ```js 66 | preload () 67 | { 68 | // This is an example of an imported bundled image. 69 | // Remember to import it at the top of this file 70 | this.load.image('logo', logoImg); 71 | 72 | // This is an example of loading a static image 73 | // from the public/assets folder: 74 | this.load.image('background', 'assets/bg.png'); 75 | } 76 | ``` 77 | 78 | When you issue the `npm run build` command, all static assets are automatically copied to the `dist/assets` folder. 79 | 80 | ## Deploying to Production 81 | 82 | After you run the `npm run build` command, your code will be built into a single bundle and saved to the `dist` folder, along with any other assets your project imported, or stored in the public assets folder. 83 | 84 | In order to deploy your game, you will need to upload *all* of the contents of the `dist` folder to a public facing web server. 85 | 86 | ## Customizing the Template 87 | 88 | ### Babel 89 | 90 | You can write modern ES6+ JavaScript and Babel will transpile it to a version of JavaScript that you want your project to support. The targeted browsers are set in the `.babelrc` file and the default currently targets all browsers with total usage over "0.25%" but excludes IE11 and Opera Mini. 91 | 92 | ``` 93 | "browsers": [ 94 | ">0.25%", 95 | "not ie 11", 96 | "not op_mini all" 97 | ] 98 | ``` 99 | 100 | ### Webpack 101 | 102 | If you want to customize your build, such as adding a new webpack loader or plugin (i.e. for loading CSS or fonts), you can modify the `webpack/config.js` file for cross-project changes, or you can modify and/or create new configuration files and target them in specific npm tasks inside of `package.json`. Please see the [Webpack documentation](https://webpack.js.org/) for more information. 103 | 104 | ## About log.js 105 | 106 | If you inspect our node scripts you will see there is a file called `log.js`. This file makes a single silent API call to a domain called `gryzor.co`. This domain is owned by Phaser Studio Inc. The domain name is a homage to one of our favorite retro games. 107 | 108 | We send the following 3 pieces of data to this API: The name of the template being used (vue, react, etc). If the build was 'dev' or 'prod' and finally the version of Phaser being used. 109 | 110 | At no point is any personal data collected or sent. We don't know about your project files, device, browser or anything else. Feel free to inspect the `log.js` file to confirm this. 111 | 112 | Why do we do this? Because being open source means we have no visible metrics about which of our templates are being used. We work hard to maintain a large and diverse set of templates for Phaser developers and this is our small anonymous way to determine if that work is actually paying off, or not. In short, it helps us ensure we're building the tools for you. 113 | 114 | However, if you don't want to send any data, you can use these commands instead: 115 | 116 | Dev: 117 | 118 | ```bash 119 | npm run dev-nolog 120 | ``` 121 | 122 | Build: 123 | 124 | ```bash 125 | npm run build-nolog 126 | ``` 127 | 128 | Or, to disable the log entirely, simply delete the file `log.js` and remove the call to it in the `scripts` section of `package.json`: 129 | 130 | Before: 131 | 132 | ```json 133 | "scripts": { 134 | "dev": "node log.js dev & dev-template-script", 135 | "build": "node log.js build & build-template-script" 136 | }, 137 | ``` 138 | 139 | After: 140 | 141 | ```json 142 | "scripts": { 143 | "dev": "dev-template-script", 144 | "build": "build-template-script" 145 | }, 146 | ``` 147 | 148 | Either of these will stop `log.js` from running. If you do decide to do this, please could you at least join our Discord and tell us which template you're using! Or send us a quick email. Either will be super-helpful, thank you. 149 | 150 | ## Join the Phaser Community! 151 | 152 | We love to see what developers like you create with Phaser! It really motivates us to keep improving. So please join our community and show-off your work 😄 153 | 154 | **Visit:** The [Phaser website](https://phaser.io) and follow on [Phaser Twitter](https://twitter.com/phaser_)
155 | **Play:** Some of the amazing games [#madewithphaser](https://twitter.com/search?q=%23madewithphaser&src=typed_query&f=live)
156 | **Learn:** [API Docs](https://newdocs.phaser.io), [Support Forum](https://phaser.discourse.group/) and [StackOverflow](https://stackoverflow.com/questions/tagged/phaser-framework)
157 | **Discord:** Join us on [Discord](https://discord.gg/phaser)
158 | **Code:** 2000+ [Examples](https://labs.phaser.io)
159 | **Read:** The [Phaser World](https://phaser.io/community/newsletter) Newsletter
160 | 161 | Created by [Phaser Studio](mailto:support@phaser.io). Powered by coffee, anime, pixels and love. 162 | 163 | The Phaser logo and characters are © 2011 - 2025 Phaser Studio Inc. 164 | 165 | All rights reserved. 166 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Phaser - Template 9 | 10 | 11 | 12 |
13 |
14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /log.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const https = require('https'); 3 | 4 | const main = async () => { 5 | const args = process.argv.slice(2); 6 | const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8')); 7 | const event = args[0] || 'unknown'; 8 | const phaserVersion = packageData.dependencies.phaser; 9 | 10 | const options = { 11 | hostname: 'gryzor.co', 12 | port: 443, 13 | path: `/v/${event}/${phaserVersion}/${packageData.name}`, 14 | method: 'GET' 15 | }; 16 | 17 | try { 18 | const req = https.request(options, (res) => { 19 | res.on('data', () => {}); 20 | res.on('end', () => { 21 | process.exit(0); 22 | }); 23 | }); 24 | 25 | req.on('error', (error) => { 26 | process.exit(1); 27 | }); 28 | 29 | req.end(); 30 | } catch (error) { 31 | // Silence is the canvas where the soul paints its most profound thoughts. 32 | process.exit(1); 33 | } 34 | } 35 | 36 | main(); 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "template-webpack", 3 | "version": "3.3.0", 4 | "main": "src/main.js", 5 | "scripts": { 6 | "dev": "node log.js dev & webpack-dev-server --config webpack/config.js --open", 7 | "build": "node log.js build & webpack --config webpack/config.prod.js", 8 | "dev-nolog": "webpack-dev-server --config webpack/config.js --open", 9 | "build-nolog": "webpack --config webpack/config.prod.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/phaserjs/template-webpack.git" 14 | }, 15 | "author": "Phaser Studio (https://phaser.io/)", 16 | "license": "MIT", 17 | "licenseUrl": "http://www.opensource.org/licenses/mit-license.php", 18 | "bugs": { 19 | "url": "https://github.com/phaserjs/template-webpack/issues" 20 | }, 21 | "homepage": "https://github.com/phaserjs/template-webpack#readme", 22 | "devDependencies": { 23 | "@babel/core": "^7.26.10", 24 | "@babel/preset-env": "^7.26.9", 25 | "babel-loader": "^10.0.0", 26 | "clean-webpack-plugin": "^4.0.0", 27 | "copy-webpack-plugin": "^13.0.0", 28 | "file-loader": "^6.2.0", 29 | "html-webpack-plugin": "^5.6.3", 30 | "raw-loader": "^4.0.2", 31 | "terser-webpack-plugin": "^5.3.14", 32 | "webpack": "^5.99.6", 33 | "webpack-cli": "^6.0.1", 34 | "webpack-dev-server": "^5.2.1", 35 | "webpack-merge": "^6.0.0" 36 | }, 37 | "dependencies": { 38 | "phaser": "^3.90.0" 39 | } 40 | } -------------------------------------------------------------------------------- /public/assets/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phaserjs/template-webpack/9260a873cce562d798d957228d2273350c28b102/public/assets/bg.png -------------------------------------------------------------------------------- /public/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phaserjs/template-webpack/9260a873cce562d798d957228d2273350c28b102/public/assets/logo.png -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phaserjs/template-webpack/9260a873cce562d798d957228d2273350c28b102/public/favicon.png -------------------------------------------------------------------------------- /public/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | color: rgba(255, 255, 255, 0.87); 5 | background-color: #000000; 6 | } 7 | 8 | #app { 9 | width: 100%; 10 | height: 100vh; 11 | overflow: hidden; 12 | display: flex; 13 | justify-content: center; 14 | align-items: center; 15 | } 16 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phaserjs/template-webpack/9260a873cce562d798d957228d2273350c28b102/screenshot.png -------------------------------------------------------------------------------- /src/game/main.js: -------------------------------------------------------------------------------- 1 | import { Boot } from './scenes/Boot'; 2 | import { Game as MainGame } from './scenes/Game'; 3 | import { GameOver } from './scenes/GameOver'; 4 | import { MainMenu } from './scenes/MainMenu'; 5 | import { Preloader } from './scenes/Preloader'; 6 | import { AUTO, Game } from 'phaser'; 7 | 8 | // Find out more information about the Game Config at: 9 | // https://docs.phaser.io/api-documentation/typedef/types-core#gameconfig 10 | const config = { 11 | type: AUTO, 12 | width: 1024, 13 | height: 768, 14 | parent: 'game-container', 15 | backgroundColor: '#028af8', 16 | scale: { 17 | mode: Phaser.Scale.FIT, 18 | autoCenter: Phaser.Scale.CENTER_BOTH 19 | }, 20 | scene: [ 21 | Boot, 22 | Preloader, 23 | MainMenu, 24 | MainGame, 25 | GameOver 26 | ] 27 | }; 28 | 29 | const StartGame = (parent) => { 30 | 31 | return new Game({ ...config, parent }); 32 | 33 | } 34 | 35 | export default StartGame; 36 | -------------------------------------------------------------------------------- /src/game/scenes/Boot.js: -------------------------------------------------------------------------------- 1 | import { Scene } from 'phaser'; 2 | 3 | export class Boot extends Scene 4 | { 5 | constructor () 6 | { 7 | super('Boot'); 8 | } 9 | 10 | preload () 11 | { 12 | // The Boot Scene is typically used to load in any assets you require for your Preloader, such as a game logo or background. 13 | // The smaller the file size of the assets, the better, as the Boot Scene itself has no preloader. 14 | 15 | this.load.image('background', 'assets/bg.png'); 16 | } 17 | 18 | create () 19 | { 20 | this.scene.start('Preloader'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/game/scenes/Game.js: -------------------------------------------------------------------------------- 1 | import { Scene } from 'phaser'; 2 | 3 | export class Game extends Scene 4 | { 5 | constructor () 6 | { 7 | super('Game'); 8 | } 9 | 10 | create () 11 | { 12 | this.cameras.main.setBackgroundColor(0x00ff00); 13 | 14 | this.add.image(512, 384, 'background').setAlpha(0.5); 15 | 16 | this.add.text(512, 384, 'Make something fun!\nand share it with us:\nsupport@phaser.io', { 17 | fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff', 18 | stroke: '#000000', strokeThickness: 8, 19 | align: 'center' 20 | }).setOrigin(0.5); 21 | 22 | this.input.once('pointerdown', () => { 23 | 24 | this.scene.start('GameOver'); 25 | 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/game/scenes/GameOver.js: -------------------------------------------------------------------------------- 1 | import { Scene } from 'phaser'; 2 | 3 | export class GameOver extends Scene 4 | { 5 | constructor () 6 | { 7 | super('GameOver'); 8 | } 9 | 10 | create () 11 | { 12 | this.cameras.main.setBackgroundColor(0xff0000); 13 | 14 | this.add.image(512, 384, 'background').setAlpha(0.5); 15 | 16 | this.add.text(512, 384, 'Game Over', { 17 | fontFamily: 'Arial Black', fontSize: 64, color: '#ffffff', 18 | stroke: '#000000', strokeThickness: 8, 19 | align: 'center' 20 | }).setOrigin(0.5); 21 | 22 | this.input.once('pointerdown', () => { 23 | 24 | this.scene.start('MainMenu'); 25 | 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/game/scenes/MainMenu.js: -------------------------------------------------------------------------------- 1 | import { Scene } from 'phaser'; 2 | 3 | export class MainMenu extends Scene 4 | { 5 | constructor () 6 | { 7 | super('MainMenu'); 8 | } 9 | 10 | create () 11 | { 12 | this.add.image(512, 384, 'background'); 13 | 14 | this.add.image(512, 300, 'logo'); 15 | 16 | this.add.text(512, 460, 'Main Menu', { 17 | fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff', 18 | stroke: '#000000', strokeThickness: 8, 19 | align: 'center' 20 | }).setOrigin(0.5); 21 | 22 | this.input.once('pointerdown', () => { 23 | 24 | this.scene.start('Game'); 25 | 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/game/scenes/Preloader.js: -------------------------------------------------------------------------------- 1 | import { Scene } from 'phaser'; 2 | 3 | export class Preloader extends Scene 4 | { 5 | constructor () 6 | { 7 | super('Preloader'); 8 | } 9 | 10 | init () 11 | { 12 | // We loaded this image in our Boot Scene, so we can display it here 13 | this.add.image(512, 384, 'background'); 14 | 15 | // A simple progress bar. This is the outline of the bar. 16 | this.add.rectangle(512, 384, 468, 32).setStrokeStyle(1, 0xffffff); 17 | 18 | // This is the progress bar itself. It will increase in size from the left based on the % of progress. 19 | const bar = this.add.rectangle(512-230, 384, 4, 28, 0xffffff); 20 | 21 | // Use the 'progress' event emitted by the LoaderPlugin to update the loading bar 22 | this.load.on('progress', (progress) => { 23 | 24 | // Update the progress bar (our bar is 464px wide, so 100% = 464px) 25 | bar.width = 4 + (460 * progress); 26 | 27 | }); 28 | } 29 | 30 | preload () 31 | { 32 | // Load the assets for the game - Replace with your own assets 33 | this.load.setPath('assets'); 34 | 35 | this.load.image('logo', 'logo.png'); 36 | } 37 | 38 | create () 39 | { 40 | // When all the assets have loaded, it's often worth creating global objects here that the rest of the game can use. 41 | // For example, you can define global animations here, so we can use them in other scenes. 42 | 43 | // Move to the MainMenu. You could also swap this for a Scene Transition, such as a camera fade. 44 | this.scene.start('MainMenu'); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import StartGame from './game/main'; 2 | 3 | document.addEventListener('DOMContentLoaded', () => { 4 | 5 | StartGame('game-container'); 6 | 7 | }); -------------------------------------------------------------------------------- /webpack/config.js: -------------------------------------------------------------------------------- 1 | const { CleanWebpackPlugin } = require("clean-webpack-plugin"); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const path = require("path"); 4 | const webpack = require("webpack"); 5 | 6 | module.exports = { 7 | mode: "development", 8 | devtool: "eval-source-map", 9 | entry: "./src/main.js", 10 | output: { 11 | path: path.resolve(process.cwd(), 'dist'), 12 | filename: "bundle.min.js" 13 | }, 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.js$/, 18 | exclude: /node_modules/, 19 | use: { 20 | loader: "babel-loader" 21 | } 22 | }, 23 | { 24 | test: [/\.vert$/, /\.frag$/], 25 | use: "raw-loader" 26 | }, 27 | { 28 | test: /\.(gif|png|jpe?g|svg|xml|glsl)$/i, 29 | use: "file-loader" 30 | } 31 | ] 32 | }, 33 | plugins: [ 34 | new CleanWebpackPlugin({ 35 | cleanOnceBeforeBuildPatterns: [path.join(__dirname, "dist/**/*")] 36 | }), 37 | new webpack.DefinePlugin({ 38 | "typeof CANVAS_RENDERER": JSON.stringify(true), 39 | "typeof WEBGL_RENDERER": JSON.stringify(true), 40 | "typeof WEBGL_DEBUG": JSON.stringify(true), 41 | "typeof EXPERIMENTAL": JSON.stringify(true), 42 | "typeof PLUGIN_3D": JSON.stringify(false), 43 | "typeof PLUGIN_CAMERA3D": JSON.stringify(false), 44 | "typeof PLUGIN_FBINSTANT": JSON.stringify(false), 45 | "typeof FEATURE_SOUND": JSON.stringify(true) 46 | }), 47 | new HtmlWebpackPlugin({ 48 | template: "./index.html" 49 | }) 50 | ] 51 | }; 52 | -------------------------------------------------------------------------------- /webpack/config.prod.js: -------------------------------------------------------------------------------- 1 | const { CleanWebpackPlugin } = require("clean-webpack-plugin"); 2 | const CopyPlugin = require('copy-webpack-plugin'); 3 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 4 | const path = require("path"); 5 | const TerserPlugin = require("terser-webpack-plugin"); 6 | const webpack = require("webpack"); 7 | 8 | const line = "---------------------------------------------------------"; 9 | const msg = `❤️❤️❤️ Tell us about your game! - games@phaser.io ❤️❤️❤️`; 10 | process.stdout.write(`${line}\n${msg}\n${line}\n`); 11 | 12 | module.exports = { 13 | mode: "production", 14 | entry: "./src/main.js", 15 | output: { 16 | path: path.resolve(process.cwd(), 'dist'), 17 | filename: "./bundle.min.js" 18 | }, 19 | devtool: false, 20 | performance: { 21 | maxEntrypointSize: 2500000, 22 | maxAssetSize: 1200000 23 | }, 24 | module: { 25 | rules: [ 26 | { 27 | test: /\.js$/, 28 | exclude: /node_modules/, 29 | use: { 30 | loader: "babel-loader" 31 | } 32 | }, 33 | { 34 | test: [/\.vert$/, /\.frag$/], 35 | use: "raw-loader" 36 | }, 37 | { 38 | test: /\.(gif|png|jpe?g|svg|xml|glsl)$/i, 39 | use: "file-loader" 40 | } 41 | ] 42 | }, 43 | optimization: { 44 | minimizer: [ 45 | new TerserPlugin({ 46 | terserOptions: { 47 | output: { 48 | comments: false 49 | } 50 | } 51 | }) 52 | ] 53 | }, 54 | plugins: [ 55 | new CleanWebpackPlugin(), 56 | new webpack.DefinePlugin({ 57 | "typeof CANVAS_RENDERER": JSON.stringify(true), 58 | "typeof WEBGL_RENDERER": JSON.stringify(true), 59 | "typeof WEBGL_DEBUG": JSON.stringify(false), 60 | "typeof EXPERIMENTAL": JSON.stringify(false), 61 | "typeof PLUGIN_3D": JSON.stringify(false), 62 | "typeof PLUGIN_CAMERA3D": JSON.stringify(false), 63 | "typeof PLUGIN_FBINSTANT": JSON.stringify(false), 64 | "typeof FEATURE_SOUND": JSON.stringify(true) 65 | }), 66 | new HtmlWebpackPlugin({ 67 | template: "./index.html" 68 | }), 69 | new CopyPlugin({ 70 | patterns: [ 71 | { from: 'public/assets', to: 'assets' }, 72 | { from: 'public/favicon.png', to: 'favicon.png' }, 73 | { from: 'public/style.css', to: 'style.css' } 74 | ], 75 | }), 76 | ] 77 | }; 78 | --------------------------------------------------------------------------------