@@ -7,21 +7,24 @@ if (process.argv.includes('--mode=dev')) {
77process . env . FLAVOR ??= `local`
88
99import * as esbuild from 'esbuild'
10+ import importFolderPlugin from 'esbuild-plugin-import-folder'
1011import ImportGlobPlugin from 'esbuild-plugin-import-glob'
1112import inlineImage from 'esbuild-plugin-inline-image'
1213import * as fs from 'fs'
1314import { load } from 'js-yaml'
1415import vscodeProblemsPatch from 'node-modules-vscode-problems-patch'
15- import * as path from 'path'
16- import { isAbsolute , join } from 'path'
16+ import * as path from 'node:path'
17+ import { isAbsolute , join } from 'node:path'
18+ import {
19+ createBlockbenchSvelteConfig ,
20+ esbuildPluginSvelte ,
21+ } from 'svelte-patching-tools/esbuildPlugin'
1722import { TextDecoder } from 'util'
18- import svelteConfig from '../svelte.config.js'
1923import assetOverridePlugin from './plugins/assetOverridePlugin'
2024import bufferPatchPlugin from './plugins/bufferPatchFunction.js'
21- import importFolderPlugin from './plugins/importFolder '
25+ import langPlugin from './plugins/lang '
2226import mcbCompressionPlugin from './plugins/mcbCompressionPlugin'
2327import packagerPlugin from './plugins/packagerPlugin'
24- import sveltePlugin from './plugins/sveltePlugin'
2528const PACKAGE = JSON . parse ( fs . readFileSync ( './package.json' , 'utf-8' ) )
2629
2730const INFO_PLUGIN : esbuild . Plugin = {
@@ -134,34 +137,7 @@ function createBanner() {
134137 return '│ ' + ' ' . repeat ( l ) + v + ' ' . repeat ( r ) + ' │'
135138 } )
136139
137- const message = `
138- # Animated Java does not work in Blockbench 5
139-
140- You will need to install and use Blockbench v4.12.6 to use Animated Java until it is updated to support 5.
141-
142- ## How to install Blockbench v4.12.6
143-
144- 1. Download the portable version of Blockbench 4.12.6 [here](https://github.com/JannisX11/blockbench/releases/download/v4.12.6/Blockbench_4.12.6_portable.exe).
145- 2. Once it's finished downloading, double click the .exe file to run it.
146-
147- If you're familiar with command line interfaces, you can use [Envbench](https://www.npmjs.com/package/envbench) to install and manage multiple Blockbench versions side by side.
148- `
149-
150- const startupCode = `(() => {
151- if (!compareVersions('5.0.0', Blockbench.version)) {
152- const message = \`${ message } \`;
153- Blockbench.showMessageBox({title: 'Animated Java - Incompatible Blockbench Version',message,width:600});
154- requestAnimationFrame(() => Plugins.registered['animated_java'].uninstall());
155- throw new Error(message);
156- }
157- })()` . trim ( )
158-
159- const banner =
160- '\n' +
161- [ header , ...lines , footer ] . map ( v => `//?? ${ v } ` ) . join ( '\n' ) +
162- '\n\n' +
163- startupCode +
164- '\n'
140+ const banner = '\n' + [ header , ...lines , footer ] . map ( v => `//?? ${ v } ` ) . join ( '\n' )
165141
166142 return {
167143 js : banner ,
@@ -205,17 +181,27 @@ const yamlPlugin: (opts: {
205181 } ,
206182} )
207183
184+ import VSCODE_SETTINGS from '../.vscode/settings.json'
185+ const IGNORED_SVELTE_WARNINGS = Object . keys (
186+ VSCODE_SETTINGS [ 'svelte.plugin.svelte.compilerWarnings' ]
187+ )
188+
208189const COMMON_CONFIG : esbuild . BuildOptions = {
209190 banner : createBanner ( ) ,
210191 entryPoints : [ './src/index.ts' ] ,
211192 outfile : `./dist/${ PACKAGE . name } .js` ,
212193 bundle : true ,
213- platform : 'node' ,
194+ platform : 'browser' ,
195+ external : [ 'node:*' ] ,
214196 loader : { '.svg' : 'dataurl' , '.ttf' : 'binary' , '.css' : 'text' } ,
215197 plugins : [
198+ langPlugin ( {
199+ languageFolder : 'src/lang' ,
200+ } ) ,
216201 // @ts -expect-error broken default import
217202 vscodeProblemsPatch . default ( ) ,
218- importFolderPlugin ,
203+ // @ts -expect-error broken default import
204+ importFolderPlugin . default ( ) ,
219205 // @ts -expect-error broken default import
220206 ImportGlobPlugin . default ( ) ,
221207 bufferPatchPlugin ( ) ,
@@ -224,15 +210,36 @@ const COMMON_CONFIG: esbuild.BuildOptions = {
224210 } ) ,
225211 INFO_PLUGIN ,
226212 yamlPlugin ( { } ) ,
227- sveltePlugin ( svelteConfig ) ,
213+ esbuildPluginSvelte (
214+ createBlockbenchSvelteConfig ( PACKAGE . name , {
215+ compilerOptions : {
216+ warningFilter ( warning : any ) {
217+ return ! IGNORED_SVELTE_WARNINGS . includes ( warning . code )
218+ } ,
219+ compatibility : {
220+ componentApi : 4 ,
221+ } ,
222+ // @ts -expect-error - not typed correctly
223+ generate : 'client' ,
224+ } ,
225+ } )
226+ ) ,
228227 packagerPlugin ( ) ,
229228 assetOverridePlugin ( ) ,
230229 mcbCompressionPlugin ( ) ,
231230 DEPENDENCY_QUARKS ,
232231 ] ,
233- alias : { svelte : 'svelte' } ,
232+ alias : {
233+ svelte : 'svelte' ,
234+ module : './.scripts/fakeModule.js' ,
235+ 'node:module' : './.scripts/fakeModule.js' ,
236+ } ,
234237 format : 'iife' ,
235238 define : DEFINES ,
239+ inject : [
240+ // Blockbench does not provide access to the global process, but some of our dependencies expect it to exist.
241+ `./.scripts/fakeProcess.js` ,
242+ ] ,
236243 treeShaking : true ,
237244}
238245
0 commit comments