Skip to content

Commit

Permalink
Update build.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin authored Sep 26, 2023
1 parent ed15be8 commit fef8b83
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import { existsSync, rmdirSync } from "fs"
import { join } from "path"

import { transform } from "esbuild"
import type { Plugin } from "vite"
import { build } from "vite"

if (existsSync(join(__dirname, "../dist")))
rmdirSync(join(__dirname, "../dist"), { recursive: true })

function minifyBundles(): Plugin {
return {
name: "minifyBundles",
renderChunk: {
order: "post",
async handler(code, chunk, outputOptions) {
if (outputOptions.format === "es" && chunk.fileName.endsWith(".mjs"))
return await transform(code, { minify: true, treeShaking: true })

return code
}
}
}
}

build({
base: "./",
build: {
Expand All @@ -34,8 +17,7 @@ build({
fileName: (_format, entry) => entry + ".mjs"
},
target: "es2017"
},
plugins: [minifyBundles()]
}
})

build({
Expand All @@ -49,6 +31,5 @@ build({
fileName: (_format, entry) => entry + ".mjs"
},
target: "es2017"
},
plugins: [minifyBundles()]
}
})

0 comments on commit fef8b83

Please sign in to comment.