Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Js minification does not work when module has exports

I do have following Errors when js file is minified

/* Minification failed. Returning unminified contents.
(36307,7-8): run-time error JS1010: Expected identifier: .
(36307,7-8): run-time error JS1195: Expected expression: .
(36817,7-8): run-time error JS1010: Expected identifier: .
(36817,7-8): run-time error JS1195: Expected expression: .
(36820,7-8): run-time error JS1010: Expected identifier: .
(36820,7-8): run-time error JS1195: Expected expression: .
 */

The JavaScript file script file below, However I found the JavaScript that contains "module.export" will not be minified and I also use online tool for minification, but the minified file does not contain "module.export" and it is removed during minification. Any help how to sort the minification problem of JavaScript file contain module.export

(function e(t, n, r) {

    module.exports = FilterCSS;

}, {
    "./default": 7,
    "./parser": 9,
    "./util": 10
}], 7: [function(require, module, exports) {
        /**
         * cssfilter
         *
         * @author ??<[email protected]>
         */

        function getDefaultWhiteList() {
            // ??????:
            // true: ?????
            // Function: function (val) { } ??true???????,?????????
            // RegExp: regexp.test(val) ??true???????,?????????
            // ??????????????
            var whiteList = {};

            whiteList['align-content'] = false; // default: auto
            whiteList['align-items'] = false; // default: auto

            *
            *
            @param {
                String
            }
            name
                *
                @param {
                    String
                }
            value
                *
                @param {
                    Object
                }
            options
                *
                @return {
                    String
                }
                */

            function onAttr(name, value, options) {
                // do nothing
            }

            /**
             * ???????????????
             *
             * @param {String} name
             * @param {String} value
             * @param {Object} options
             * @return {String}
             */
            function onIgnoreAttr(name, value, options) {
                // do nothing
            }

            var REGEXP_URL_JAVASCRIPT = /javascript\s*\:/img;

            /**
             * ?????
             *
             * @param {String} name
             * @param {String} value
             * @return {String}
             */
            function safeAttrValue(name, value) {
                if (REGEXP_URL_JAVASCRIPT.test(value)) return '';
                return value;
            }


            exports.whiteList = getDefaultWhiteList();
            exports.getDefaultWhiteList = getDefaultWhiteList;
            exports.onAttr = onAttr;
            exports.onIgnoreAttr = onIgnoreAttr;
            exports.safeAttrValue = safeAttrValue;

        }, {}], 8: [function(require, module, exports) {
        /**
         * cssfilter
         *
         * @author ??<[email protected]>
         */

        var DEFAULT = require('./default');
        var FilterCSS = require('./css');


        /**
         * XSS??
         *
         * @param {String} css ????CSS??
         * @param {Object} options ??:whiteList, onAttr, onIgnoreAttr
         * @return {String}
         */
        function filterCSS(html, options) {
            var xss = new FilterCSS(options);
            return xss.process(html);
        }


        // ??
        exports = module.exports = filterCSS;
        exports.FilterCSS = FilterCSS;
        for (var i in DEFAULT) exports[i] = DEFAULT[i];

        // ???????
        if (typeof window !== 'undefined') {
            window.filterCSS = module.exports;
        }

    }, {
        "./css": 6,
        "./default": 7
    }], 9: [function(require, module, exports) {
            /**
             * cssfilter
             *
             * @author ??<[email protected]>
             */

            var _ = require('./util');
like image 541
Mudasir Nabi Avatar asked Oct 16 '25 16:10

Mudasir Nabi


1 Answers

Try like this:

['module'].exports = FilterCSS;

Also this:

[module].exports = FilterCSS;

It worked for me, but no idea why. Before this epiphany, I had solve similar issues with global variables, using something like this:

window['module'].exports=......

But, at least in my case, module was no global. No idea how I came up with this, and less idea how it worked. I'm new with javascript.

like image 97
Alexy Dumenigo Aguila Avatar answered Oct 18 '25 05:10

Alexy Dumenigo Aguila



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!