Web Dev Solutions

Catalin Mititiuc

const { createServer } = require('esbuild-server'); const path = require('node:path'); const resolveImportedSvg = { name: 'resolveImportedSvg', setup(build) { build.onResolve({ filter: /\.svg$/ }, args => { return { path: path.resolve('public', args.path), }; }); } } const server = createServer( { bundle: true, define: { 'env': `"${process.env.NODE_ENV || 'dev'}"`, }, entryPoints: ['src/*.js'], ...(process.env.NODE_ENV !== 'test') && { outdir: 'build' }, plugins: [resolveImportedSvg], loader: { '.svg': 'file' }, metafile: true, assetNames: 'assets/images/[name]-[hash]', }, { static: 'public', ...(process.env.NODE_ENV === 'test') && { port: 3005, injectLiveReload: false, watch: false } } ); const buildStart = Date.now(); server .start() .then((d) => { console.log(`Build completed in ${Date.now() - buildStart}ms`); }) .catch(() => { console.error('Build failed'); }); console.log(`${process.env.NODE_ENV === 'test' ? 'Test' : 'Development'} server running at ${server.url}`);