javascriptnode.jsuglifyjsuglifyjs2

Can uglify-js remove require and export statements?


I'm using uglify-js to minify the source code. I want to remove

const moment = require('moment');

const PouchDB = require('pouchdb');

module.exports = Chart;

statements of the original source code. Is it possible? Or is there any other compressor tool supports this?

I use the code as below in Node.js.

'use strict'
const moment = require('moment');
const PouchDB = require('pouchdb');
const defaultcachetime = 12; // hours
const VERIFIED = 3;
const UNIQUCOUNTER = 1;


var caches = {};
var cachechange = {};

function Chart(path, credentials, user){

}

module.exports = Chart;

The output contains

"use strict";const moment=require("moment"),PouchDB=require("pouchdb") return a},module.exports=Chart;

Thank you for helping


Solution

  • Managed to overcome the challenge by doing

    1. Browserify to convert Require and Import keywords to FE parsable code.

    2. Minify JS code with Uglify

    Hope it helps with anyone who might be facing the same challenge.