Skip to content

Commit

Permalink
Reduced build size
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennard Fonteijn authored and LennardF1989 committed Nov 23, 2022
1 parent 08cbb7c commit 6fc9e31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions packaging/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ await packContractsAndChallenges()

const { version, revisionIdent } = require("../package.json")

const jsonAsCompressedTextPlugin = {
name: "jsonAsCompressedTextPlugin",

setup(build) {
let fs = require("fs")

build.onLoad({ filter: /\.json$/ }, async (args) => {
const text = await fs.promises.readFile(args.path)

return {
contents: JSON.stringify(JSON.parse(text)),
loader: "text",
}
})
},
}

await e.build({
entryPoints: ["components/index.ts"],
bundle: true,
Expand Down Expand Up @@ -59,6 +76,7 @@ await e.build({
},
sourcemap: "external",
plugins: [
jsonAsCompressedTextPlugin,
esbuildPluginLicense({
thirdParty: {
output: {
Expand All @@ -67,7 +85,4 @@ await e.build({
},
}),
],
loader: {
".json": "text"
}
})
4 changes: 2 additions & 2 deletions packaging/devLoader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import picocolors from "picocolors"
import { packContractsAndChallenges } from "./buildTasks.mjs"
import { createRequire, Module } from "module"
import { readFileSync }from "fs"
import { readFileSync } from "fs"

// this `require` instance will be hijacked by `esbuild-register` so we can load
// TS files as if they were JS in a CommonJS environment
Expand Down Expand Up @@ -49,7 +49,7 @@ register()

const resolveTextFile = function (module, path) {
const content = readFileSync(path).toString()

module.exports = content
}

Expand Down

0 comments on commit 6fc9e31

Please sign in to comment.