Skip to content

Commit

Permalink
Remove debug from prod build
Browse files Browse the repository at this point in the history
Reduces the bundled package by 33%! From 18kb to 12kb.
  • Loading branch information
mauriciopoppe committed Jun 15, 2024
1 parent 03a7e3e commit c69c91b
Show file tree
Hide file tree
Showing 11 changed files with 5,448 additions and 8,023 deletions.
6 changes: 0 additions & 6 deletions babel.config.cjs

This file was deleted.

13,368 changes: 5,384 additions & 7,984 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
"point-line-distance": "^1.0.0"
},
"devDependencies": {
"@babel/cli": "^7.18.10",
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.10",
"@babel/preset-typescript": "^7.24.7",
"@jest/globals": "^29.7.0",
"@types/debug": "^4.1.12",
"@types/gl-vec3": "^1.1.4",
Expand Down
10 changes: 9 additions & 1 deletion src/Face.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { dot, add, subtract, cross, copy, length, scale, scaleAndAdd, normalize } from 'gl-vec3'
import dot from 'gl-vec3/dot'
import add from 'gl-vec3/add'
import copy from 'gl-vec3/copy'
import subtract from 'gl-vec3/subtract'
import cross from 'gl-vec3/cross'
import length from 'gl-vec3/length'
import scale from 'gl-vec3/scale'
import scaleAndAdd from 'gl-vec3/scaleAndAdd'
import normalize from 'gl-vec3/normalize'
import { default as $debug } from 'debug'

import { HalfEdge } from './HalfEdge'
Expand Down
3 changes: 2 additions & 1 deletion src/HalfEdge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { distance, squaredDistance } from 'gl-vec3'
import distance from 'gl-vec3/distance'
import squaredDistance from 'gl-vec3/squaredDistance'
import { Face } from './Face'
import { Vertex } from './Vertex'
import { default as $debug } from 'debug'
Expand Down
4 changes: 2 additions & 2 deletions src/QuickHull.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pointLineDistance from 'point-line-distance'
import getPlaneNormal from 'get-plane-normal'
import { dot } from 'gl-vec3'
import dot from 'gl-vec3/dot'
import { default as $debug } from 'debug'

import { Point, Face as IFace } from './types'
Expand All @@ -18,7 +18,7 @@ enum MergeType {
NonConvex
}

export interface QuickHullOptions {
export class QuickHullOptions {
skipTriangulation ?: boolean
}

Expand Down
7 changes: 7 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// debug replaces the module debug in prod.
export default function debug() {
function innerDebugger() { }
innerDebugger.enabled = false
return innerDebugger
}

45 changes: 33 additions & 12 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,39 @@ declare module 'debug' {
export default function debug(args: any): any
}

declare module 'gl-vec3' {
export function add(out: number[], a: number[], b: number[]): number[];
export function dot(a: number[], b: number[]): number;
export function normalize(out: number[], a: number[]): number[];
export function subtract(out: number[], a: number[], b: number[]): number[];
export function distance(a: number[], b: number[]): number;
export function squaredDistance(a: number[], b: number[]): number;
export function cross(out: number[], a: number[], b: number[]): number[];
export function copy(out: number[], a: number[]): number[];
export function length(a: number[]): number;
export function scale(out: number[], a: number[], b: number): number[];
export function scaleAndAdd(out: number[], a: number[], b: number[], scale: number): number[];
declare module 'gl-vec3/add' {
export default function add(out: number[], a: number[], b: number[]): number[];
}

declare module 'gl-vec3/dot' {
export default function dot(a: number[], b: number[]): number;
}
declare module 'gl-vec3/normalize' {
export default function normalize(out: number[], a: number[]): number[];
}
declare module 'gl-vec3/subtract' {
export default function subtract(out: number[], a: number[], b: number[]): number[];
}
declare module 'gl-vec3/distance' {
export default function distance(a: number[], b: number[]): number;
}
declare module 'gl-vec3/squaredDistance' {
export default function squaredDistance(a: number[], b: number[]): number;
}
declare module 'gl-vec3/cross' {
export default function cross(out: number[], a: number[], b: number[]): number[];
}
declare module 'gl-vec3/copy' {
export default function copy(out: number[], a: number[]): number[];
}
declare module 'gl-vec3/length' {
export default function length(a: number[]): number;
}
declare module 'gl-vec3/scale' {
export default function scale(out: number[], a: number[], b: number): number[];
}
declare module 'gl-vec3/scaleAndAdd' {
export default function scaleAndAdd(out: number[], a: number[], b: number[], scale: number): number[];
}

declare module 'point-line-distance' {
Expand Down
2 changes: 0 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-env jest */

import assert from 'assert'
import { expect, describe, it } from '@jest/globals'
import qh, { isPointInsideHull, QuickHull, Face, Point } from '../src/'
Expand Down
10 changes: 0 additions & 10 deletions test/index.types.ts

This file was deleted.

12 changes: 11 additions & 1 deletion webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
const path = require('path')
const webpack = require('webpack')
const isProduction = process.env.NODE_ENV === 'production'

const plugins = []
if (isProduction) {
plugins.push(new webpack.NormalModuleReplacementPlugin(
/debug/,
'./debug.ts'
))
}

module.exports = {
entry: './src/index.ts',
mode: isProduction ? 'production' : 'development',
Expand Down Expand Up @@ -29,5 +38,6 @@ module.exports = {
},
stats: {
errorDetails: true
}
},
plugins
}

0 comments on commit c69c91b

Please sign in to comment.