Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-05-28 14:45:20 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-05-28 14:45:20 -0700
commite8fbe161e473a949f776f89d94e9816a64cd3114 (patch)
tree5def4f8e9e499d3280bc83c5f23edd642850193c /server.cjs
parenta34cd1a5414eec5a059c5f20a3940bf4ef6b977e (diff)
Import mapsheets.svg
Diffstat (limited to 'server.cjs')
-rw-r--r--server.cjs61
1 files changed, 57 insertions, 4 deletions
diff --git a/server.cjs b/server.cjs
index 1910f2b..b41f7eb 100644
--- a/server.cjs
+++ b/server.cjs
@@ -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 },