mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-24 09:37:05 +08:00
This is already used for more than just themes, and we plan to extend its usage even further
31 lines
786 B
JavaScript
Vendored
31 lines
786 B
JavaScript
Vendored
import { minify as terserMinify } from "terser";
|
|
|
|
export default function discourseTerser({ opts }) {
|
|
return {
|
|
name: "discourse-terser",
|
|
async renderChunk(code, chunk, outputOptions) {
|
|
if (!opts.minify) {
|
|
return;
|
|
}
|
|
|
|
// Based on https://github.com/ember-cli/ember-cli-terser/blob/28df3d90a5/index.js#L12-L26
|
|
const defaultOptions = {
|
|
sourceMap:
|
|
outputOptions.sourcemap === true ||
|
|
typeof outputOptions.sourcemap === "string",
|
|
compress: {
|
|
negate_iife: false,
|
|
sequences: 30,
|
|
drop_debugger: false,
|
|
},
|
|
output: {
|
|
semicolons: false,
|
|
},
|
|
};
|
|
|
|
defaultOptions.module = true;
|
|
|
|
return await terserMinify(code, defaultOptions);
|
|
},
|
|
};
|
|
}
|