@@ -16,43 +16,49 @@ talked about briefly.
1616Install UglifyJS
1717----------------
1818
19- UglifyJS is available as an `Node.js `_ npm module and can be installed using
20- npm. First, you need to `install Node.js `_. Afterwards you can install UglifyJS
21- using npm:
19+ UglifyJS is available as a `Node.js `_ module. First, you need to `install Node.js `_
20+ and then, decide the installation method: global or local.
21+
22+ Global Installation
23+ ~~~~~~~~~~~~~~~~~~~
24+
25+ The global installation method makes all your projects use the very same UglifyJS
26+ version, which simplifies its maintenance. Open your command console and execute
27+ the following command (you may need to run it as a root user):
2228
2329.. code-block :: bash
2430
2531 $ npm install -g uglify-js
2632
27- This command will install UglifyJS globally and you may need to run it as
28- a root user.
33+ Now you can execute the global ``uglifyjs `` command anywhere on your system:
2934
30- .. note ::
35+ .. code-block :: bash
3136
32- It's also possible to install UglifyJS inside your project only. To do
33- this, install it without the ``-g `` option and specify the path where
34- to put the module:
37+ $ uglifyjs --help
3538
36- .. code-block :: bash
39+ Local Installation
40+ ~~~~~~~~~~~~~~~~~~
3741
38- $ cd /path/to/symfony
39- $ mkdir app/Resources/node_modules
40- $ npm install uglify-js --prefix app/Resources
42+ It's also possible to install UglifyJS inside your project only, which is useful
43+ when your project requires an specific UglifyJS version. To do this, install it
44+ without the `` -g `` option and specify the path where to put the module:
4145
42- It is recommended that you install UglifyJS in your ``app/Resources `` folder
43- and add the ``node_modules `` folder to version control. Alternatively,
44- you can create an npm `package.json `_ file and specify your dependencies
45- there.
46+ .. code-block :: bash
4647
47- Depending on your installation method, you should either be able to execute
48- the `` uglifyjs `` executable globally, or execute the physical file that lives
49- in the `` node_modules `` directory:
48+ $ cd /path/to/your/symfony/project
49+ $ mkdir app/Resources/node_modules
50+ $ npm install uglify-js --prefix app/Resources
5051
51- .. code-block :: bash
52+ It is recommended that you install UglifyJS in your ``app/Resources `` folder and
53+ add the ``node_modules `` folder to version control. Alternatively, you can create
54+ an npm `package.json `_ file and specify your dependencies there.
5255
53- $ uglifyjs --help
56+ Now you can execute the ``uglifyjs `` command that lives in the ``node_modules ``
57+ directory:
5458
55- $ ./app/Resources/node_modules/.bin/uglifyjs --help
59+ .. code-block :: bash
60+
61+ $ " ./app/Resources/node_modules/.bin/uglifyjs" --help
5662
5763 Configure the ``uglifyjs2 `` Filter
5864----------------------------------
@@ -96,8 +102,7 @@ your JavaScripts:
96102 .. note ::
97103
98104 The path where UglifyJS is installed may vary depending on your system.
99- To find out where npm stores the ``bin `` folder, you can use the following
100- command:
105+ To find out where npm stores the ``bin `` folder, execute the following command:
101106
102107 .. code-block :: bash
103108
@@ -154,8 +159,8 @@ can configure its location using the ``node`` key:
154159 Minify your Assets
155160------------------
156161
157- In order to use UglifyJS on your assets, you need to apply it to them. Since
158- your assets are a part of the view layer, this work is done in your templates :
162+ In order to apply UglifyJS on your assets, add the `` filter `` option in the
163+ asset tags of your templates to tell Assetic to use the `` uglifyjs2 `` filter :
159164
160165.. configuration-block ::
161166
@@ -178,8 +183,7 @@ your assets are a part of the view layer, this work is done in your templates:
178183
179184 The above example assumes that you have a bundle called AppBundle and your
180185 JavaScript files are in the ``Resources/public/js `` directory under your
181- bundle. This isn't important however - you can include your JavaScript
182- files no matter where they are.
186+ bundle. However you can include your JavaScript files no matter where they are.
183187
184188With the addition of the ``uglifyjs2 `` filter to the asset tags above, you
185189should now see minified JavaScripts coming over the wire much faster.
@@ -216,12 +220,9 @@ and :ref:`dump your assetic assets <cookbook-assetic-dump-prod>`.
216220
217221.. tip ::
218222
219- Instead of adding the filter to the asset tags, you can also globally
220- enable it by adding the ``apply_to `` attribute to the filter configuration, for
221- example in the ``uglifyjs2 `` filter ``apply_to: "\.js$" ``. To only have
222- the filter applied in production, add this to the ``config_prod `` file
223- rather than the common config file. For details on applying filters by
224- file extension, see :ref: `cookbook-assetic-apply-to `.
223+ Instead of adding the filters to the asset tags, you can also configure which
224+ filters to apply for each file in your application configuration file.
225+ See :ref: `cookbook-assetic-apply-to ` for more details.
225226
226227Install, Configure and Use UglifyCSS
227228------------------------------------
@@ -231,8 +232,14 @@ the node package is installed:
231232
232233.. code-block :: bash
233234
235+ # global installation
234236 $ npm install -g uglifycss
235237
238+ # local installation
239+ $ cd /path/to/your/symfony/project
240+ $ mkdir app/Resources/node_modules
241+ $ npm install uglifycss --prefix app/Resources
242+
236243 Next, add the configuration for this filter:
237244
238245.. configuration-block ::
0 commit comments