1

我在使用 AjaxMin 的 MinifyJavaScript 方法缩小javascript 文件时遇到问题。

未缩小的代码

if (typeof define === 'function' && define.amd) {
        define(['moment'], function (moment) {
            root.moment = factory(moment)
            return root.moment
        })
    } else if (typeof exports === 'object') {
        module.exports = factory(require('moment'))
    } else {
        root.moment = factory(root.moment)
    }

缩小代码

if(typeof define=="function"&&define.amd)define(["moment"],function(i){return n.moment=t(i),n.moment});else if(typeof exports=="object"){module{}.exports=t(require("moment"))}else n.moment=t(n.moment)}

在缩小代码中,在模块对象之后添加“{}”,例如:module{}.exports 但它应该是 module.exports

在缩小文件之前还有几个文件: 1. jquery-3.3.1.min.js 2. moment.min.js

所有文件都捆绑在一个文件中,然后完成缩小。

4

1 回答 1

0

我认为这是问题的原因

  1. ajaxmin 源代码模块好像是保留字
  2. if/else 范围没有正确编译到输出。

这似乎导致了这个问题

var blockType = AjaxMin.BlockTypeModule.FormatInvariant
(moduleScope.ScopeName.IfNullOrWhiteSpace(AjaxMin.ModuleNameImplicit));

解决方法(这是我在项目中所做的):

  • 您可以将该字符串替换module{}.module.
  • 使用三元运算符而不是 if/else(很可能这将跳过整个块的替换)
  • 使用该文件的缩小版本(这将跳过缩小)
于 2018-11-15T07:01:57.873 回答