pages/lib/filters/minifyJs.js

18 lines
320 B
JavaScript
Raw Normal View History

2023-04-02 08:31:07 +00:00
const { minify } = require('terser');
2024-10-04 09:45:51 +00:00
module.exports = async (code) => {
2023-04-02 08:31:07 +00:00
if (process.env.NODE_ENV === 'production') {
2024-10-04 09:45:51 +00:00
const minified = await minify(code);
2023-04-02 08:31:07 +00:00
if (minified.error) {
console.error('Terser error: ', minified.error);
return code;
}
return minified.code;
}
return code;
};