javascript 使用 PHPStorm 压缩 CSS 和 JS 代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13911815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:09:28  来源:igfitidea点击:

Compress CSS & JS code with PHPStorm?

javascriptcssphpstorm

提问by Jooxa

I'm using PHPStorm. This is very great software for web developers.

我正在使用 PHPStorm。对于 Web 开发人员来说,这是一款非常棒的软件。

When I want to compress my CSS & JS files in PHPStorm , I can't find any option in PHPStorm.

当我想在 PHPStorm 中压缩我的 CSS 和 JS 文件时,我在 PHPStorm 中找不到任何选项。

So, Please tell me how to compress CSS & JS code in PHPStorm.

所以,请告诉我如何在 PHPStorm 中压缩 CSS 和 JS 代码。

回答by web-nomad

Found Assets Compressorplugin. See if it helps.

找到资产压缩器插件。看看它是否有帮助。

EDIT - Changed to the new link as pointed by @spade

编辑 - 更改为@spade 指出的新链接

回答by Dmitry

PHPStorm supports minification by File Watchers. It supports integration with the YUI Compressor "out of the box", but it has some problems, e.g., with calc() function. My solution is to use minifier:

PHPStorm 支持通过File Watchers 进行缩小。它支持“开箱即用”与 YUI Compressor 的集成,但它有一些问题,例如,与 calc() 函数。我的解决方案是使用minifier

  1. Repeat the steps to install Node.js and npm from JetBrains manual
  2. Install minifier like YUI Compressor in manual (npm install minifier)
  3. Minifier documentation says: "Installing through npm will create a binary (minify) in the usual locations", but I have not found it (perhaps it is not created on Windows). Index.jsfile can be executed via node index.jscommand, but PHPStorm does not maintain this way ("Please set program to run!" error will be thrown). So I created .bat file with the following content:
  1. 重复安装JetBrains 手册中的Node.js 和 npm 的步骤
  2. 在手册中安装像 YUI Compressor 这样的 minifier ( npm install minifier)
  3. Minifier 文档说:“通过 npm 安装将在通常的位置创建一个二进制文件 (minify)”,但我还没有找到它(也许它不是在 Windows 上创建的)。Index.js文件可以通过node index.js命令执行,但 PHPStorm 不保持这种方式(“请设置程序运行!”错误将被抛出)。所以我创建了 .bat 文件,内容如下:

.

.

echo off
node path\to\minifier\index.js %*
  1. Then in PHPStorm watcher settings in Programinput field we set path to the .bat file. Note that Minifier uses a different method for setting the output path, so we have to change Argumentsfield: $FileName$ --output $FileNameWithoutExtension$.min.css
  1. 然后在Program输入字段的PHPStorm 观察器设置中,我们设置 .bat 文件的路径。请注意,Minifier 使用不同的方法来设置输出路径,因此我们必须更改Arguments字段:$FileName$ --output $FileNameWithoutExtension$.min.css

回答by CrazyCoder

See the related feature requests:

查看相关功能请求:

  • WEB-2138Support automatic JavaScript and CSS minification
  • WEB-2125Pre- and post-deployment commands
  • WEB-2138支持自动 JavaScript 和 CSS 缩小
  • WEB-2125部署前和部署后命令

At the moment you can use third-party tools/plug-ins like suggested by @Pushpesh.

目前,您可以使用@Pushpesh 建议的第三方工具/插件。