javascript實現貪吃蛇小遊戲

源碼地址:https://github.com/qmdx00/Snake ,請不要吝嗇star。
html

首先畫出UML類圖:node

用es6的語法,建立項目結構:webpack

配置webpack:git

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel-loader'
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './index.html'
        })
    ],
    devServer: {
        contentBase: path.join(__dirname, './release'),
        open: true,
        port: 4000
    }
}

入口文件爲index.js,構建生成目錄爲distes6

配置啓動腳本:package.jsongithub

{
  "name": "snake",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack-dev-server --config ./webpack.dev.config.js --mode development",
    "build": "webpack --config ./webpack.dev.config.js --mode production"
  },
  "author": "yuanweimin",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-latest": "^6.24.1",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5"
  }
}

安裝依賴後執行 npm run buildweb

便可生成最終代碼。具體代碼請見github,喜歡的給個star哦。npm

相關文章
相關標籤/搜索