Web前端培训:15个Javascript压缩工具

Web前端培训:15个Javascript压缩工具

在Web前端开发过程中,我们经常需要编写大量的JavaScript代码,为了提高代码的运行效率和减少文件大小,我们需要对JavaScript代码进行压缩,本文将介绍15个常用的Javascript压缩工具,帮助你快速压缩JavaScript代码。

Web前端培训:15个Javascript压缩工具

1、UglifyJS

UglifyJS是一个非常流行的JavaScript压缩工具,它可以将JavaScript代码压缩到最小,同时保持代码的可读性,使用UglifyJS的方法如下:

uglifyjs input.js -o output.js -c --mangle

input.js是需要压缩的JavaScript文件,output.js是压缩后的输出文件,--mangle选项用于混淆变量名。

2、Google Closure Compiler

Google Closure Compiler是一个由谷歌开发的JavaScript编译器,它可以将JavaScript代码转换为浏览器可以执行的低级代码,Google Closure Compiler还具有代码压缩功能,使用方法如下:

Web前端培训:15个Javascript压缩工具

java -jar closure-compiler.jar --language_in=ECMASCRIPT6_STRICT --js output.js --compilation_level ADVANCED --warning_level VERBOSE --define "DEBUG" --formatting PRETTY_PRINTING

output.js是需要压缩的JavaScript文件,其他参数用于控制编译过程。

3、YUI Compressor

YUI Compressor是一个基于CSS预处理器YUI Compressor的JavaScript压缩工具,它可以将JavaScript代码压缩到最小,同时保持代码的可读性,使用方法如下:

yuicompressor input.js -o output.js

input.js是需要压缩的JavaScript文件,output.js是压缩后的输出文件。

4、JSMin

Web前端培训:15个Javascript压缩工具

JSMin是一个简单的JavaScript压缩工具,它可以将JavaScript代码压缩到最小,同时保持代码的可读性,使用方法如下:

var f = JSMin(code);

code是需要压缩的JavaScript代码,f是压缩后的代码。

5、Babel

Babel是一个广泛使用的JavaScript编译器,它可以将ES6及以上版本的JavaScript代码转换为向后兼容的JavaScript代码,Babel还具有代码压缩功能,使用方法如下:

npx babel input.js --out-file output.js --presets @babel/preset-env --compact false --minified true --source-maps false --no-comments true --no-stringify false --no-source-map true --comments false --minified false --moduleIdsMode Simple --legacyConstPrecedence true --extractComments false --preserveConst enums minmax maxmind minimize mangle toplevel_rename calcNames names exports localIdent nameShorthand pure beautify arrowThis boolid expString stopVar minExpr number parseInt parseFloat makeRegExp recast regExpToRe replaceTernary computedProp computedKey triggerCallSuffix dynamicImport importNameSpaceSpecifier dynamicImportNamespaceSpecifier importDefaultSpecifier namedExports exportNamedLocals exportNamespaceFromSpecifier exportSpecifierMap exportSpecifierSet functionSent flagInlineRequires inlineRequires localHash localModuleIds moduleIds localNames sourceMaps sourceFileName systemStrings template stringTemplateToString toDefined toStringRaw utilConcat utilIdentity utilUndefined utilDeprecate utilIsObject utilNonEnumerable utilLast utilMath utilNumber utilObject utilParseInt utilPush utilRxutilRefCountedValue utilSet utilWeak utilValueOf varDecl variableDeclarator variables vars arrayLiteral objectLiteral propertyProperty shorthandProperty computedProperty restSpread restElement spreadProperty arguments callExpression newExpression assignment expression statement expressionStatement program program binary arithmetic arithmetic operator unary arithmetic operator logical logical operator bitwise bitwise operator relational relational operator equality equality operator relation and or not instanceof in type of delete inc dec decrement ++ += ++= + += * *= *= % modulo remainder exit log not a not_1 not_1n not_a not_an instanceof is defined hasOwnProperty propertyIsEnumerable constructor prototype valueOf apply bind bindAsArray join iterator entries keys values forEach of fromentries reduce reverse sort sortBy find findIndex from iterate map filter every some every_value join reduce reduceRight flat map flat mapDeep compact pure extract assertType assert assertWarning assertError count countBy sum sumBy max min findKey findValue findIndexBy findIndex findLastIndex findLastIndexOf findLastIndexOfIndexOf index includes includesIndex indexOf lastIndexOf lastIndexOfIndexOf search substr slice sliceWith startWith endWith pad trim trimLeft trimRight reverse split compact_array compactArray sort_object sortObject reverse_array reverseArray join_array joinArray push pop shift unshift splice spliceInsert spliceRemove reverse reverseEach sortBy orderBy sortedIndex sortedIndexBy sortedKey sortedValues group by groupByOrder groupByOrderSort group by each reduce reduceRight forEach forEach_right for_own forIn forAry forOwn of from arguments argumentsToArray argsToArray rest restArguments restArgumentsToArray restSlice restSliceWith restUnshift restPush assign assignTo this yield yieldFrom yieldAll yieldAllStar then chain sequence destructuring mapping extend merge clone deepAssign defaults defaultsDeep partial has defaultToIterableIterable next entries values select pick pickBy pickByOrder get getOrNull getOrUndefined getOrThrow getOrThrowIfNull hasIn hasInWith path pathOr root resolve resolveLookup resolvePath reject rejectWith rejectAll rejectPromise rejectPromiseWith all isEmpty isEmptyWith isNil isNilWith isType isTypeOf like match matchAll matchSome likeIndex likeKey matchValue matchPattern matchPatternWith matches contains containsWith startsWith equals equalsWith indexOf indexOfFrom indexFrom startsWithEndsWith endsWith trim trimStart trimEnd trimBoth escape html jsx regex json xml css url query params headers body content title meta charset referer origin host status location accept acceptCharset acceptEncoding acceptLanguage cookie cookieJar withCredentials proxy auth username password server key certificate ca cert passphrase clientkey clientcert strictSSL host name port domain protocol http https ws wss request response on stream pipe fetch setTimeout setTimeoutClear clearInterval clearImmediate console log warn error assert print info debug time now performance mark markTime timeEnd timeStamp timezone date format dateAdd dateSubtract dayStart dayEnd hoursMinutesSeconds milliseconds days weeks months years add subtract round up down multiply divide abs ceil floor log base random randomBytes randomInt randomNormal randomExponential randomGlow randomGlowShuffle round halfPi PI e E INFINITY NAN MAX_SAFE_INTEGER MIN_SAFE_INTEGER MAX_VALUE MIN_VALUE Number BigInt Int8Array Uint8Array Uint8ClampedArray Int16Array Int32Array Float32Array Float64Array BigInt64Array BigUint64Array Date RegExp ArrayBuffer DataView Set Map WeakMap WeakSet Proxy Intl Error Event Promise Generator GeneratorFunction Function AsyncFunction ReadableStream WritableStream Transform Duplex Stream pipeline pipelineRate through take takeWhile takeEvery takeLatest throttle throttleTimely map mapValues mapEntries for await of yieldAwaitOf promiseAll promiseResolve allSettled race raceOnce settle settlePromise any some every someValue someValues findIndex fromEntries findIndexFrom findLastIndex findLastIndexFrom findKey findValue indexBy indexByOrder indexByOrderSort indexByKey indexByValue join joinWith joinWithSeparator split splitWith splitLimit remove removeAt removeAll removeFrom splice spliceInsert spliceRemove reverse reverseEach sortBy orderBy sortedIndex sortedIndexBy sortedKey sortedValues group by groupByOrder groupByOrderSort group by each reduce reduceRight forEach forEach_right for_own forIn forAry forOwn of from arguments argsToArray rest restArguments restArgumentsToArray restSlice restSliceWith restUnshift restPush assign assignTo this yield yieldFrom yieldAll yieldAllStar then chain sequence destructuring mapping extend merge clone deepAssign defaults defaultsDeep partial has defaultToIterableIterable next entries values select pick pickBy pickByOrder get getOrNull getOrUndefined getOrThrow getOrThrowIfNull hasIn hasInWith path pathOr root resolve resolveLookup resolvePath reject rejectWith rejectAll rejectPromise rejectPromiseWith all isEmpty isEmptyWith isNil isNilWith isType isTypeOf like match matchAll matchSome likeIndex likeKey matchValue matchPattern matchPatternWith matches contains containsWith startsWith equals equalsWith indexOf indexOfFrom indexFrom startsWithEndsWith endsWith trim trimStart trimEnd trimBoth escape html jsx regex json xml css url query params headers body content title meta charset referer origin host status location accept acceptCharset acceptEncoding acceptLanguage cookie cookieJar withCredentials proxy auth username password server key certificate ca cert passphrase clientkey clientcert strictSSL host name port domain protocol http https ws wss request response on stream pipe fetch setTimeout setTimeoutClear clearInterval clearImmediate console log warn error assert print info debug time now performance mark markTime timeEnd timeStamp timezone date format dateAdd dateSubtract dayStart dayEnd hoursMinutesSeconds milliseconds days weeks months years add subtract round up down multiply divide abs ceil floor log base random randomBytes randomInt randomNormal randomExponential randomG

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/134179.html

(0)
K-seoK-seoSEO优化员
上一篇 2023年12月16日 11:57
下一篇 2023年12月16日 12:00

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入