Skip to content

Commit bd1c695

Browse files
authored
✨ Feature: Reduce Bundle Size (#199)
* remove unneeded code by dependencies * separate resolution changes into their own plugin from the info plugin
1 parent e8bb4ee commit bd1c695

10 files changed

+46
-11
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules\\typescript\\lib"
3+
}

src/components/boneConfigDialog.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</script>
1313

1414
<script lang="ts">
15-
import { NbtCompound, NbtTag } from 'deepslate'
15+
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
1616
1717
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1818

src/components/vanillaBlockDisplayConfigDialog.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212

1313
<script lang="ts">
14-
import { NbtCompound, NbtTag } from 'deepslate'
14+
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
1515
1616
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1717

src/components/vanillaItemDisplayConfigDialog.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212

1313
<script lang="ts">
14-
import { NbtCompound, NbtTag } from 'deepslate'
14+
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
1515
1616
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1717

src/nodeConfigs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NbtByte, NbtCompound, NbtFloat, NbtInt, NbtString, NbtTag } from 'deepslate'
1+
import { NbtByte, NbtCompound, NbtFloat, NbtInt, NbtString, NbtTag } from 'deepslate/lib/nbt'
22
import {
33
IBlueprintBoneConfigJSON,
44
IBlueprintCameraConfigJSON,

src/systems/datapackCompiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import datapackTemplate from './animated_java.mcb'
55
import { AnyRenderedNode, IRenderedRig } from './rigRenderer'
66
import { IRenderedAnimation } from './animationRenderer'
77
import { Variant } from '../variants'
8-
import { NbtCompound, NbtFloat, NbtInt, NbtList, NbtString } from 'deepslate'
8+
import { NbtCompound, NbtFloat, NbtInt, NbtList, NbtString } from 'deepslate/lib/nbt'
99
import {
1010
arrayToNbtFloatArray,
1111
matrixToNbtFloatArray,

src/systems/modelDataFixerUpper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IBlueprintFormatJSON, getDefaultProjectSettings } from '../blueprintFor
22
import { BoneConfig } from '../nodeConfigs'
33
import { PACKAGE } from '../constants'
44
import { openUnexpectedErrorDialog } from '../interface/unexpectedErrorDialog'
5-
import { NbtCompound, NbtList, NbtString, NbtTag } from 'deepslate'
5+
import { NbtCompound, NbtList, NbtString, NbtTag } from 'deepslate/lib/nbt'
66

77
export function process(model: any): any {
88
console.log('Running MDFU...', JSON.parse(JSON.stringify(model)))

src/systems/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NbtFloat, NbtList } from 'deepslate'
1+
import { NbtFloat, NbtList } from 'deepslate/lib/nbt'
22
import {
33
AsyncZipOptions,
44
AsyncZippable,

tools/esbuild.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ImportGlobPlugin from 'esbuild-plugin-import-glob'
1919
import packagerPlugin from './plugins/packagerPlugin'
2020
import inlineWorkerPlugin from './plugins/workerPlugin'
2121
import assetOverridePlugin from './plugins/assetOverridePlugin'
22-
22+
import path from 'path'
2323
const PACKAGE = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
2424

2525
const INFO_PLUGIN: esbuild.Plugin = {
@@ -42,7 +42,35 @@ const INFO_PLUGIN: esbuild.Plugin = {
4242
})
4343
},
4444
}
45-
45+
const DEPENDENCY_QUARKS: esbuild.Plugin = {
46+
name: 'dependency-quarks',
47+
setup(build) {
48+
build.onResolve({ filter: /^three/ }, args => {
49+
if (args.path === 'three') {
50+
return { path: 'three', external: true }
51+
} else {
52+
return {
53+
path: require.resolve(args.path),
54+
}
55+
}
56+
})
57+
build.onResolve({ filter: /^deepslate\// }, args => {
58+
// esbuild respects the package.json "exports" field
59+
// but the version of typescript we're using doesn't
60+
// so we need to resolve the path manually
61+
const file_path = path.resolve(
62+
process.cwd(),
63+
path.dirname(require.resolve('deepslate')),
64+
'..',
65+
args.path.split('/').slice(1).join('/'),
66+
'index.js'
67+
)
68+
return {
69+
path: file_path,
70+
}
71+
})
72+
},
73+
}
4674
function createBanner() {
4775
function wrap(s: string, width: number) {
4876
return s.replace(new RegExp(`(?![^\\n]{1,${width}}$)([^\\n]{1,${width}})\\s`, 'g'), '$1\n')
@@ -189,9 +217,11 @@ const devConfig: esbuild.BuildOptions = {
189217
packagerPlugin(),
190218
inlineWorkerPlugin(devWorkerConfig),
191219
assetOverridePlugin(),
220+
DEPENDENCY_QUARKS,
192221
],
193222
format: 'iife',
194223
define: DEFINES,
224+
treeShaking: true,
195225
}
196226

197227
const prodConfig: esbuild.BuildOptions = {
@@ -214,12 +244,14 @@ const prodConfig: esbuild.BuildOptions = {
214244
packagerPlugin(),
215245
inlineWorkerPlugin({}),
216246
assetOverridePlugin(),
247+
DEPENDENCY_QUARKS,
217248
],
218249
keepNames: true,
219250
banner: createBanner(),
220251
drop: ['debugger'],
221252
format: 'iife',
222253
define: DEFINES,
254+
treeShaking: true,
223255
metafile: true,
224256
}
225257

types/blockbench-types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
//// <reference types="blockbench-types"/>
2-
/// <reference path="D:/github-repos/snavesutit/blockbench-types/types/index.d.ts"/>
1+
/// <reference types="blockbench-types"/>
2+
//// <reference path="D:/github-repos/snavesutit/blockbench-types/types/index.d.ts"/>

0 commit comments

Comments
 (0)