mirror of
https://github.com/swc-project/swc.git
synced 2024-12-03 00:54:25 +03:00
29 lines
586 B
JavaScript
29 lines
586 B
JavaScript
|
import { minify } from "terser";
|
||
|
|
||
|
try {
|
||
|
const code = process.argv[1];
|
||
|
|
||
|
const output = await minify(code, {
|
||
|
sourceMap: {
|
||
|
filename: 'input.js',
|
||
|
includeSources: true,
|
||
|
},
|
||
|
compress: false,
|
||
|
mangle: false,
|
||
|
});
|
||
|
|
||
|
console.log(JSON.stringify({
|
||
|
code: output.code,
|
||
|
map: output.map,
|
||
|
}))
|
||
|
} catch (e) {
|
||
|
// Ignore syntax error
|
||
|
if (e.toString().includes("SyntaxError")) {
|
||
|
console.log(JSON.stringify({
|
||
|
code: '',
|
||
|
map: '{}',
|
||
|
}));
|
||
|
} else {
|
||
|
throw e;
|
||
|
}
|
||
|
}
|