The term minification or compression means removing all unnecessary characters, such as spaces, new lines, comments without changing the functionality of the source code. At the development and debugging stage, these characters improve the code readability. However at the production stage, they become unnecessary for code execution but only increase the size of code to be transferred.
Before you start
- Install Node.js.
- Install and activate the NodeJS and File Watchers repository plugins on the Plugins page as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
- If you are going to use YUI Compressor or Closure Compiler, download and install Java Runtime Environment (JRE):
- JRE version 1.4 or higher for YUI Compressor.
- JRE version 7 for Closure Compiler.
Installing a minification tool
- To install UglifyJS
Open the built-in RubyMine Terminal ( ) and type
npm install uglify-jsor
npm install uglify-js@<version>. Learn more from UglifyJS Official website.
- To install YUI Compressor
Follow the instructions on YUI Compressor Official website.
- To install Closure Compiler
Follow the instructions on Closure Compiler Official website.
Integrating a minification tool with RubyMine
To use a minifier in RubyMine, you need to configure it as a File Watcher. For each supported minifier, RubyMine provides a predefined File Watcher template. To run a minifier in your project, create a project-specific File Watcher based on the relevant template.
- Open the File Watchers page by choosing for Windows and Linux or for macOS.
- Click and choose the tool-specific File Watcher template from the list:
- In the New Watcher Dialog that opens, specify the path to the relevant executable file or
.jararchive in the Program field:
compiler.jarfor Closure Compiler.
yuicompressor-<version>.jarfor YUI Compressor JS.
- Optionally, customize the behaviour of the File Watcher.
- Make sure the checkbox next to the File Watcher is selected, which indicates that the File Watcher is enabled.
Running a minification tool