Minify Css and Js

12. August 2022PhpStorm

Minify Css

You can configure a File Watcher in the PhpStorm settings (Ctrl + Alt + S) > Tools > File Watchers. There you can add a new SCSS File Watcher and add

File Watcher Configuration

Program: sass
Arguments: --style=compressed $FileName$:../../Public/Css/$FileNameWithoutExtension$.min.css

Minify JavaScript

For minifying JavaScript install terser via

Install terser

sudo npm install -g terser

After that you can add the following code to the scripts part of the composer.json and execute it via composer minifyjs.

Script to minify JavaScript for composer.json

"minifyjs": "cd packages/template/Resources/Public/JavaScript && for file in `pwd`/*.js; do terser $file -m -c > `basename $file .js`.min.js; done && rm *.min.min.js || true"