search
HomeDevelopment ToolsVSCodeHow to compress js code in vscode

How to compress js code in vscode

Dec 12, 2019 pm 02:47 PM
jsvscode

How to compress js code in vscode

vscode压缩js代码的方法:

1、在拓展商店里搜索“minify”,安装,安装成功后点重新加载

2、使用:F1运行文件缩小器Minify压缩js代码。

使用Minify的方法介绍:

缩小您的js,css和html文件以节省传输带宽。直接调用每个缩小器,以允许传递设置:

JS: uglify -js v2.7.4

CSS: clean-css v3.4.21

HTML: html-minifier v3.2.2

使用F1 运行文件缩小器Minify。

包含Javascript和CSS文件的文件夹可以{dirname}.min.[css|js]使用F1 缩小为一个文件Minify Directory。可以为Javascript和CSS减少一个目录是可以接受的。

(可选)在已存在匹配的缩小文件(和/或目录)时,在保存时运行minify。启用您的用户或工作空间设置。设置默认值如下所示:

"minify.minifyExistingOnSave": false,"minify.js": {
	"mangle": true,
	"compress": {
		"sequences": true,
		"properties": true,
		"dead_code": true,
		"drop_debugger": true,
		"unsafe": false,
		"unsafe_comps": false,
		"conditionals": true,
		"comparisons": true,
		"evaluate": true,
		"booleans": true,
		"loops": true,
		"unused": true,
		"hoist_funs": true,
		"keep_fargs": true,
		"keep_fnames": false,
		"hoist_vars": false,
		"if_return": true,
		"join_vars": true,
		"collapse_vars": false,
		"reduce_vars": false,
		"side_effects": true,
		"pure_getters": false,
		"pure_funcs": null,
		"negate_iife": false,
		"drop_console": false,
		"passes": 1,
		"global_defs": {}
	},
	"output": {
		"ascii_only": false,
		"inline_script": false,
		"max_line_len": 32000,
		"braces": false,
		"semicolons": true,
		"comments": false,
		"shebang": true,
		"preamble": null,
		"quote_style": "best"
	}},"minify.css": {
	"advanced": true,
	"aggressiveMerging": true,
	"compatibility": "*",
	"inliner": {},
	"keepBreaks": false,
	"keepSpecialComments": "*",
	"mediaMerging": true,
	"processImport": true,
	"processImportFrom": ["all"],
	"rebase": true,
	"restructuring": true,
	"root": "${workspaceRoot}",
	"roundingPrecision": 2,
	"semanticMerging": false,
	"shorthandCompacting": true},"minify.html": {
	"caseSensitive": false,
	"collapseBooleanAttributes": true,
	"collapseWhitespace": true,
	"conservativeCollapse": false,
	"customAttrAssign": [],
	"customAttrCollapse": "",
	"customAttrSurround": [],
	"customEventAttributes": [ "^on[a-z]{3,}$" ],
	"decodeEntities": false,
	"html5": true,
	"ignoreCustomComments": [ "^!" ],
	"ignoreCustomFragments": ["<%[\\s\\S]*?%>", "<\\?[\\s\\S]*?\\?>"],
	"includeAutoGeneratedTags": true,
	"keepClosingSlash": false,
	"maxLineLength": false,
	"minifyCSS": true, //uses minify.css settings if true
	"minifyJS": true, //uses minify.js settings if true
	"minifyURLs": false,
	"preserveLineBreaks": false,
	"preventAttributesEscaping": false,
	"processConditionalComments": false,
	"processScripts": [],
	"quoteCharacter": "\"",
	"removeAttributeQuotes": false,
	"removeComments": false,
	"removeEmptyAttributes": false,
	"removeEmptyElements": false,
	"removeOptionalTags": false,
	"removeRedundantAttributes": false,
	"removeScriptTypeAttributes": false,
	"removeStyleLinkTypeAttributes": false,
	"sortAttributes": false,
	"sortClassName": false,
	"useShortDoctype": false}

minifiy.css.root接受“ ${workspaceRoot}/ some / path”定义内部@import绝对根。

由于html-minifier还采用了clean-css和uglify-js,设置minifyJS或minifyCSS以true意志嵌入你为那些minifiers自动提供的设置。如果要使用一些其他方法,可以提供自己的设置作为对象。

PHP中文网,有大量免费的vscode入门教程,欢迎大家学习!

The above is the detailed content of How to compress js code in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Best Practices for Writing JavaScript Code with VSCodeBest Practices for Writing JavaScript Code with VSCodeMay 15, 2025 pm 09:45 PM

Best practices for writing JavaScript code in VSCode include: 1) Install Prettier, ESLint, and JavaScript (ES6) codesnippets extensions, 2) Configure launch.json files for debugging, and 3) Use modern JavaScript features and optimization loops to improve performance. With these settings and tricks, you can develop JavaScript code more efficiently in VSCode.

Use VSCode to perform version fallback operation of codeUse VSCode to perform version fallback operation of codeMay 15, 2025 pm 09:42 PM

In VSCode, you can use Git for code version fallback. 1. Use gitreset--hardHEAD~1 to fall back to the previous version. 2. Use gitreset--hard to fall back to a specific commit. 3. Use gitrevert to safely fall back without changing history.

Use tips and recommendations for the VSCode plug-in marketUse tips and recommendations for the VSCode plug-in marketMay 15, 2025 pm 09:39 PM

To better utilize the VSCode plug-in market, first use advanced search functions to filter the plug-in, secondly install and uninstall the plug-in, and finally make full use of the plug-in functions and maintain them regularly. 1. Use keywords and advanced search functions (ratings, downloads, release dates) to filter plugins. 2. Click "Install" to install the plug-in, and click "Uninstall" to uninstall the plug-in. 3. It is recommended to use Prettier, GitLens and LiveShare plugins, and regularly review and update the plugins to optimize performance.

An effective way to resolve Git commit conflicts in VSCodeAn effective way to resolve Git commit conflicts in VSCodeMay 15, 2025 pm 09:36 PM

Handling Git commit conflicts in VSCode can be effectively resolved through the following steps: 1. Identify the conflicting file, and VSCode will be highlighted in red. 2. Manually edit the code between conflict marks and decide to retain, delete or merge. 3. Keep branches small and focused to reduce conflicts. 4. Use GitLens extension to understand code history. 5. Use VSCode to build-in Git commands, such as gitmerge--abort or gitreset--hard. 6. Avoid relying on automatic merge tools and carefully check the merge results. 7. Delete all conflict marks to avoid compilation errors. With these methods and tricks, you can handle Git conflicts efficiently in VSCode.

How to manually install plugin packages in VSCodeHow to manually install plugin packages in VSCodeMay 15, 2025 pm 09:33 PM

The steps to manually install the plug-in package in VSCode are: 1. Download the .vsix file of the plug-in; 2. Open VSCode and press Ctrl Shift P (Windows/Linux) or Cmd Shift P (Mac) to call up the command panel; 3. Enter and select Extensions:InstallfromVSIX..., then select .vsix file and install. Manually installing plug-ins provides a flexible way to install, especially when the network is restricted or the plug-in market is unavailable, but attention needs to be paid to file security and possible dependencies.

Environment configuration for running Ruby code in VSCodeEnvironment configuration for running Ruby code in VSCodeMay 15, 2025 pm 09:30 PM

Configuring the Ruby development environment in VSCode requires the following steps: 1. Install Ruby: Download and install from the official website or using RubyInstaller. 2. Install the plug-in: Install CodeRunner and Ruby plug-ins in VSCode. 3. Set up the debugging environment: Install the DebuggerforRuby plug-in and create a launch.json file in the .vscode folder for configuration. This way, you can write, run, and debug Ruby code efficiently in VSCode.

Efficient way to install VSCode plug-in in batchesEfficient way to install VSCode plug-in in batchesMay 15, 2025 pm 09:27 PM

An efficient way to install VSCode plugins in batches is to use command line tools. The specific steps include: 1. Export the plug-in list: run code--list-extensions>extensions.txt. 2. Bulk installation of plug-ins: Run catextensions.txt|xargs-n1code--install-extension, so that plug-in configurations can be easily synchronized between different environments.

View Git history and changes in VSCodeView Git history and changes in VSCodeMay 15, 2025 pm 09:24 PM

How to view Git history and changes in VSCode include: 1. Open VSCode and make sure the project has initialized the Git repository. 2. Click the "Source Code Management" icon in the left sidebar. 3. Select "...(more options)" and click "Git:ShowGitOutput". 4. View commit history and file changes. 5. Right-click the file and select "Git:ShowFileHistory" to view the file change history. Through these steps, you can efficiently view Git history and changes in VSCode to improve development efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment