Closed ghost closed 3 days ago
Well, I suppose that this would be the tool to be used! It seems more fitting upon inspection, anyhow. I believe as long as its minification process does not come with a critical error that would ruin the code itself, it can grow alongside Deno, couldn't it?
We already use swc
in Deno. Again this is still a long term goal, as there are a load of other things we need to do (including ones related to bundling, see: #4549) before this became a priority, some of which would block this (source maps for example).
This potentially could be considered now that we have moved over bundling to swc.
minification is on the swc roadmap but not implemented yet
Would be great to see minification for deno bundle
! I use deno bundle
for my client side TS code, so it'd be great to minify it as well
In the meantime, you may use esbuild
, an extremely fast JavaScript minifier written in Go, to minify your Deno bundles:
$ deno bundle https://deno.land/std@0.79.0/http/file_server.ts | esbuild --minify > file_server.min.js
$ deno run --allow-net --allow-read file_server.min.js
Other JavaScript minifiers (eg terser
) may have issues like Unexpected character '#'
- See https://github.com/terser/terser/issues/702
Sounds like a shortcut or alias can be made from that! @pierredewilde
For information they're some work in swc for minify https://github.com/swc-project/swc/pull/1302
In the meantime, you may use
esbuild
, an extremely fast JavaScript minifier written in Go, to minify your Deno bundles:$ deno bundle https://deno.land/std@0.79.0/http/file_server.ts | esbuild --minify > file_server.min.js $ deno run --allow-net --allow-read file_server.min.js
Other JavaScript minifiers (eg
terser
) may have issues likeUnexpected character '#'
- See terser/terser#702
esbuild now supports deno! https://github.com/evanw/esbuild/releases/tag/v0.11.11
Thanks @David-Else . That is a module that only works in a script though. I installed it and then found esbuild
did nothing.
@MichaelCurrin You ran this as a .js
file and it worked?
import * as esbuild from 'https://deno.land/x/esbuild@v0.11.11/mod.js'
const ts = 'let hasProcess: boolean = typeof process != "null"'
const result = await esbuild.transform(ts, { loader: 'ts', logLevel: 'warning' })
console.log('result:', result)
esbuild.stop()
Does it not install the esbuild
binary? I suggest you have a look at the later comments here: https://github.com/evanw/esbuild/issues/936 and comment if you have problems. You need to use the API rather than the CLI https://esbuild.github.io/api/
I have not actually sorted it myself yet, but it is in the 'in box' :)
@David-Else I ran this
deno install -f --allow-read 'https://deno.land/x/esbuild@v0.11.11/mod.js'
Which installs to ~/.deno/bin
.
Then running esbuild
in the shell does nothing not even an error or version, because the mod script has no CLI entrypoint.
I could rewrite as a TS file using the API, but I have a bunch of command line flags that work already if I use npx esbuild
on the main branch, so I'm not going rewrite those now. I'll wait until a CLI format ready. Makefile on feature branch
Please keep the information on topic. If you want to discuss esbuild under Deno, we have a discussion forum.
Any update on this?
If deno uses swc, and swc allows for config files to set things like minification, Is it possible to just expose that for configuring the compile
command. (might also be a good idea to include that in the new deno.json
config file like there is for tsconfig
)
https://swc.rs/docs/configuration/minification
Not really, as the way Deno interfaces with swc is not via a configuration file, but instead by directly interfacing to the Rust APIs, and the configuration is quite opinionated.
That being said, it could be something that the wider community could contribute by adding a --minify
flag to deno bundle
and deno compile
and would require familiarity with the Rust API of swc. We would want to ensure that the source maps are right and proper for deno bundle
.
If this gets implemented, would you also add a minify?: boolean
option to Deno.emit
?
In https://github.com/denoland/deno/issues/16149 @kitsonk explained why it's not going to happen. I'd close this issue in favor of https://github.com/denoland/deno/issues/15463
deno bundle
was removed in Deno 2.
Similar to how Deno uses a TypeScript compiler when running code, users should have the option when bundling to minify their compiled files for better performance. The argument after bundle could be
-m
or-minify
. We could see if the minifier would beuglify
, which from what I've heard is normally used withnpm
.Any thoughts?