index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
path: root/server.cjs
diff options
Diffstat (limited to 'server.cjs')
-rw-r--r-- | server.cjs | 61 |
1 files changed, 57 insertions, 4 deletions
@@ -1,4 +1,7 @@ const { createServer } = require('esbuild-server'); +const fs = require('node:fs'); +const path = require('node:path'); + // const { IncomingMessage } = require('node:http'); // const { URL } = require('node:url'); // const path = require('node:path'); @@ -40,20 +43,70 @@ const { createServer } = require('esbuild-server'); // console.log('path', path.normalize(path.join('public', 'assets/css/damage_block.css'))) +let version; + +const svgUseCacheBust = { + name: 'svgUseCacheBust', + setup(build) { + // build.onStart(() => { + // version = Math.random(); + // console.log('svg use cache bust online', version); + // const file = fs.readFileSync('./public/assets/images/scenario-side_show.svg', {encoding: 'utf-8'}); + // console.log('file', file); + // }); + + // version = Math.random(); + build.onResolve({ filter: /\.svg$/ }, args => { + return { + path: path.resolve('public', args.path), + }; + }); + + build.onEnd(result => { + // console.log('metafile', JSON.stringify(result.metafile, null, 2)); + + // for (k in result.metafile.outputs) { + // console.log(result.metafile.outputs[k]); + // } + + // const filename = Object.keys(result.metafile.outputs).find(key => { + // return result.metafile.outputs[key].inputs['public/assets/images/scenario-side_show.svg']; + // }); + + // console.log('filename', filename); + + // const file = fs.readFileSync(filename, { encoding: 'utf-8' }); + + // const mapsheets = Object.keys(result.metafile.outputs).find(key => { + // return result.metafile.outputs[key].inputs['public/assets/images/mapsheets.svg']; + // }); + + // console.log('mapsheets', path.basename(mapsheets)); + + // const newFile = file.replaceAll('mapsheets.svg', path.basename(mapsheets)); + + // fs.writeFileSync(filename, newFile); + }); + } +} + const server = createServer( { bundle: true, define: { 'env': `"${process.env.NODE_ENV || 'dev'}"`, }, - entryPoints: ['src/index.js', 'src/map.js', 'src/soldier_record_block.js'], + entryPoints: ['src/*.js'], // outdir: 'build', ...(process.env.NODE_ENV !== 'test') && { outdir: 'build' }, - // loader: { - // '.svg': 'file' - // }, + plugins: [svgUseCacheBust], + loader: { + '.svg': 'file' + }, + metafile: true, + assetNames: 'assets/images/[name]-[hash]', }, { // http: { IncomingMessage: Request }, |