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 🙏

© 2025 – Pkg Stats / Ryan Hefner

wa-map-optimizer-vite

v1.1.31

Published

Vite plugin for WA Map Optimizer

Readme

WA Map Optimizer Vite Plugin

Vite plugin to optimize WorkAdventure Tiled (.tmj) maps using wa-map-optimizer, and to wire Tiled "script" and "mapImage" properties to your built assets automatically.

  • Recursively discovers .tmj maps
  • Validates map structure (using @workadventure/tiled-map-type-guard)
  • Runs wa-map-optimizer during Vite build
  • Rewrites the "script" map property to the hashed JS asset built by Vite
  • Copies the file referenced by "mapImage" alongside the optimized map and updates the property

Installation

npm i -D wa-map-optimizer-vite

Quick start

  1. In Tiled, add optional custom properties on your map:
  • script (string): relative path to a JS/TS entry you want built by Vite
  • mapImage (string): relative path to an image you want copied next to the optimized map

Example (excerpt of your .tmj):

{
  "properties": [
    { "name": "script", "type": "string", "value": "./scripts/myScene.ts" },
    { "name": "mapImage", "type": "string", "value": "./images/preview.png" }
  ]
}
  1. Configure Vite to discover maps, declare script entries, and attach the optimizer plugins:
// vite.config.ts
import { defineConfig } from 'vite';
import { getMaps, getMapsScripts, getMapsOptimizers, type OptimizeOptions } from 'wa-map-optimizer-vite';

// Discover maps (pass the folder containing your .tmj files)
const maps = getMaps('maps');

// Optional: customize optimizer options (passed to wa-map-optimizer)
const optimizeOptions: OptimizeOptions = {
  logs: 1, // 0=silent ... 3=verbose (see wa-map-optimizer LogLevel)
  // output: { path: 'dist' } // defaults to 'dist'
};

export default defineConfig({
  build: {
    rollupOptions: {
      // Expose each Tiled "script" as a named entry so Vite builds hashed assets
      input: {
        ...getMapsScripts(maps)
      }
    },
    // outDir should match your base output (defaults to 'dist')
    // outDir: 'dist'
  },
  plugins: [
    // One optimizer plugin instance per map
    ...getMapsOptimizers(maps, optimizeOptions)
  ]
});
  1. Build your project:
vite build

After the build:

  • Each map is optimized into dist/<original_map_dir>/.tmj
  • If a map has a "mapImage" property, the image is copied next to the optimized map and the property is updated
  • If a map has a "script" property, it is replaced by the path to the corresponding hashed asset under dist/assets

How it works

  • getMaps walks the provided directory (skipping dist and node_modules), validates .tmj files, and returns a Map of path -> ITiledMap
  • getMapsScripts returns a Rollup/Vite input object mapping each map script name to its source path
  • getMapsOptimizers returns an array of Vite plugins; during writeBundle each plugin:
    • runs wa-map-optimizer to generate the optimized .tmj and tileset chunks
    • optionally copies the mapImage file next to the optimized map and updates the property
    • reads the built assets folder (dist/assets) to locate the hashed JS for the declared script and rewrites the map "script" property accordingly

Notes:

  • The base output folder defaults to dist. You can override via OptimizeOptions.output.path
  • Tileset names are automatically prefixed with -chunk and suffixed with a short shake256 digest