diff --git a/src/commands/build.ts b/src/commands/build.ts index b7e3534..951f7a5 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -4,13 +4,14 @@ import { resolve } from 'node:path'; import { glob } from 'glob'; import { configDotenv } from 'dotenv'; import assert from 'node:assert'; -import { imageLoader, validExtensions } from '../plugins/imageLoader'; import defaultEsbuild from '../utilities/defaultEsbuildConfig'; import { require } from '../utilities/require'; import { pathExists, pathExistsSync } from 'find-up'; import { mkdir, writeFile } from 'fs/promises'; import * as Preprocessor from '../utilities/preprocessor'; import { bold, magentaBright } from 'colorette'; +const validExtensions = ['.ts', '.js', '.json', '.png', '.jpg', '.jpeg', '.webp']; + type BuildOptions = { /** @@ -156,7 +157,7 @@ export async function build(options: Record) { //https://esbuild.github.io/content-types/#tsconfig-json await esbuild.build({ entryPoints, - plugins: [imageLoader, ...(buildConfig.esbuildPlugins ?? [])], + plugins: [...(buildConfig.esbuildPlugins ?? [])], ...defaultEsbuild(buildConfig.format!, buildConfig.tsconfig), define, dropLabels: [buildConfig.mode === 'production' ? '__DEV__' : '__PROD__', ...buildConfig.dropLabels!], diff --git a/src/plugins/imageLoader.ts b/src/plugins/imageLoader.ts deleted file mode 100644 index ec553d1..0000000 --- a/src/plugins/imageLoader.ts +++ /dev/null @@ -1,39 +0,0 @@ -import fs from 'fs/promises'; -import path from 'node:path'; -import { require } from '../utilities/require.js'; -import { type Plugin } from 'esbuild'; -import { basename } from 'node:path'; - -export const validExtensions = ['.ts', '.js', '.json', '.png', '.jpg', '.jpeg', '.webp']; - -//https://github.com/evanw/esbuild/issues/1051 -export const imageLoader = { - name: 'attachment-loader', - setup: (b) => { - const filter = new RegExp(`\.${validExtensions.slice(3).join('|')}$`); - b.onResolve({ filter }, (args) => { - //if the module is being imported, resolve the path and transform to the js stub - if (args.importer) { - const newPath = path - .format({ ...path.parse(args.path), base: '', ext: '.js' }) - .split(path.sep) - .join(path.posix.sep); - return { path: newPath, namespace: 'attachment-loader', external: true }; - } - // if the file is actually the attachment, resolve the full dir - return { path: require.resolve(args.path, { paths: [args.resolveDir] }), namespace: 'attachment-loader' }; - }); - - b.onLoad({ filter: /.*/, namespace: 'attachment-loader' }, async (args) => { - const base64 = await fs.readFile(args.path).then((s) => s.toString('base64')); - return { - contents: ` - var __toBuffer = (base64) => Buffer.from(base64, "base64"); - module.exports = { - name: '${basename(args.path)}', - attachment: __toBuffer("${base64}") - }`, - }; - }); - }, -} satisfies Plugin;