npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

phaser-assets-webpack-plugin

v2.2.1

Published

Load assets automatically for Phaser3

Downloads

4

Readme

PhaserAssetsWebpackPlugin

Phaser 3.x npm license

A Webpack plugin to load assets automatically for Phaser3. It watches the directories along your setting and exports a json file that listed the assets information.

Usage

Install:

$ npm install phaser-assets-webpack-plugin

Define into webpack.config.js:

const PhaserAssetsWebpackPlugin = require('phaser-assets-webpack-plugin')
// ...
{
  entry: {
    ...
  },
  output: {
    ...
  },
  plugins: [
    new PhaserAssetsWebpackPlugin({
      patterns: [
        { type: 'image', dir: '/img', rule: /^\w+\.png$/ },
        { type: 'audio', dir: '/audio', rule: /^\w+\.(m4a|ogg)$/ }
      ],
      documentRoot: './public',
      output: './src/assets.json'
    })
  ]
}

Settings:

|Key|Default|What is| |---|---|---| |patterns|Required|An Array of assets settings| |documentRoot|'public'|The path to the document root directory.| |output|'assets.json'|The path to the json file to output.| |spriteSheetSettingsFileName|'settings.json'|The name of settings file for spritesheet.|

Patterns:

|Key|Required|What is| |---|---|---| |type|Yes|Method name for Phaser::Loader. image will be spritesheet automatically when it is.| |prefix|No|Prefix for the assets key name.| |dir|Yes|Assets directory from document root. It can be started with / or ./.| |rule|Yes|Name pattern of files to be assets.| |callback|No|Callback function after loaded. Given arg that Array of the loaded data.|

CLI

// config file
module.exports = {
  patterns: [
    { type: 'image', dir: '/img', rule: /^\w+\.png$/ },
    { type: 'audio', dir: '/audio', rule: /^\w+\.(m4a|ogg)$/ }
  ],
  documentRoot: './public',
  output: './src/assets.json'
}
$ phaser-assets --config <path to config file> --watch

Use the exported json in Phaser3

An example of the exported json.

{
  "image": [
    ["title", "/img/title.png"]
  ],
  "spritesheet": [
    ["player", "/img/player.png", { "frameWidth": 16, "frameHeight": 16, "startFrame": 0, "endFrame": 3 }]
  ],
  "audio": [
    ["bgm", ["/audio/bgm.m4a", "/audio/bgm.ogg"]]
  ]
}

The key names based on each file name. ( player.png => [prefix]player )

The Data can be imported and used for Phaser::Loader as is.

import assets from './assets.json'
Object.keys(assets).forEach(methodName => {
  assets[methodName].forEach(args => scene.load[methodName](...args)
})

The json file will be regenerated automatically when added or removed files while webpack is watching.

Spritesheet setting

Just define num of horizontal and vertical for each spritesheet into JSON file located same dir as assets.

- img/
  - player.png
  - setting.json
[
  ["player.png", 3, 1]
]

The image will be spritesheet if the setting is exsists.

Requirements

  • Webpack5

I'm not sure if this will be working on other versions. Please make an issue or PR if need it.

[Examples] Projects that using this plugin