Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: minify at first try, no es5 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { basename, dirname } from 'https://deno.land/std/path/mod.ts'
import { writeAllSync } from 'https://deno.land/std/streams/write_all.ts'

import { exe } from 'https://av.prod.archive.org/js/util/cmd.js'
import { warn } from 'https://av.prod.archive.org/js/util/log.js'
import { log, warn } from 'https://av.prod.archive.org/js/util/log.js'

/*
Bundles and transpiles JS files.
Expand Down Expand Up @@ -140,7 +140,8 @@ async function builder() {
outdir: OPTS.outdir,
sourcemap: true,
loader: { '.js': 'jsx' },
minify: ES6 ? OPTS.minify : false, // if we're making ES5, we'll minify later
minify: true,
// minify: ES6 ? OPTS.minify : false, // if we're making ES5, we'll minify later
format: ES6 ? 'iife' : OPTS.format,
banner: ES6 ? { js: `${OPTS.banner}\n${OPTS.regenerator_inline}` } : {},
footer: ES6 ? { js: OPTS.footer } : {},
Expand Down Expand Up @@ -184,15 +185,15 @@ async function convertToES5(result) {
await Promise.all(
outputs.map(async (srcfile) => {
// warn('SWC ES5 THIS', Deno.readTextFileSync(srcfile))
const output = OPTS.format === 'iife' ?
await swc.transform(Deno.readTextFileSync(srcfile), {
jsc: { target: 'es5' },
sourceMaps: true,
module: { type: OPTS.format === 'iife' ? 'commonjs' : 'es6' },
// Ran into a bug using SWC's minifier on ESBuild's output. Instead of minfying here,
// do another ESBuild pass later only for minification
// minify: true,
}) : { code: Deno.readTextFileSync(srcfile) }
// const output = OPTS.format === 'iife' ?
// await swc.transform(Deno.readTextFileSync(srcfile), {
// jsc: { target: 'es5' },
// sourceMaps: true,
// module: { type: OPTS.format === 'iife' ? 'commonjs' : 'es6' },
// // Ran into a bug using SWC's minifier on ESBuild's output. Instead of minfying here,
// // do another ESBuild pass later only for minification
// // minify: true,
// }) : { code: Deno.readTextFileSync(srcfile) }

if (OPTS.regenerator_inline)
output.code = output.code.replace(/require\("regenerator-runtime"\)/, 'regeneratorRuntime')
Expand All @@ -201,11 +202,11 @@ async function convertToES5(result) {

// Minify again using esbuild, because we can't trust SWC's minifier.
// Also, add any banner/footer to each JS file, as well as sourcemap URL.
output.code = (await esbuild.transform(output.code, {
minify: OPTS.minify,
target: OPTS.format === 'iife' ? 'es5' : 'es6',
logLevel: OPTS.verbose ? 'verbose' : 'silent',
})).code
// output.code = (await esbuild.transform(output.code, {
// minify: OPTS.minify,
// target: OPTS.format === 'iife' ? 'es5' : 'es6',
// logLevel: OPTS.verbose ? 'verbose' : 'silent',
// })).code

const dstfile = OPTS.names_always_end_with_min
? `${OPTS.outdir}/${basename(srcfile, '.js')}.min.js`
Expand Down