17

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

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

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

2

3 Answers 3

21

Found Assets Compressor plugin. See if it helps.

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

Sign up to request clarification or add additional context in comments.

3 Comments

I installed it but the plugin doesn't generate a minified document. Nothing happens
Click "Refactor >> Compress" to compress any file. This is a great plugin, definitely an up for the response.
As of phpstorm 2019.1.2 I get an error warning which cause this plugin to malfunction.
4

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:

  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.js file can be executed via node index.js command, 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:

.

echo off
node path\to\minifier\index.js %*
  1. Then in PHPStorm watcher settings in Program input 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 Arguments field: $FileName$ --output $FileNameWithoutExtension$.min.css

1 Comment

Unfortunately, it seems this has been deprecated.
1

See the related feature requests:

  • WEB-2138 Support automatic JavaScript and CSS minification
  • WEB-2125 Pre- and post-deployment commands

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.