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

Allow javascript modules to also have template literals minified #178

Merged
merged 7 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ Default: `false`

Only minify [tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) (instead of all template literals).

#### `allowModules`

Type: `boolean`
Default: `false`

By default javascript modules are not handled. By setting `allowModules` to true, javascript modules will also have template literals minified.

### `writeFiles()`

The plugin has no options but is required to write out in-memory sources to disk. This must be performed separately because esbuild currently has no way to access or modify build output without setting the `write` build option to false.
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ESTreeMapExtra<M = ESTreeMap> = {
interface MinifyOptions {
taggedOnly?: boolean;
keepComments?: boolean;
allowModules?: boolean;
}

// Same encode/decode as esbuild
Expand All @@ -36,6 +37,7 @@ export function minify(code: string, opts: MinifyOptions = {}): MagicString {
next: true,
loc: true,
ranges: true,
module: opts.allowModules ?? false,
maxmilton marked this conversation as resolved.
Show resolved Hide resolved

onComment(type, value, _start, _end, loc) {
if (
Expand Down