@@ -16,43 +16,49 @@ talked about briefly.
16
16
Install UglifyJS
17
17
----------------
18
18
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):
22
28
23
29
.. code-block :: bash
24
30
25
31
$ npm install -g uglify-js
26
32
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:
29
34
30
- .. note ::
35
+ .. code-block :: bash
31
36
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
35
38
36
- .. code-block :: bash
39
+ Local Installation
40
+ ~~~~~~~~~~~~~~~~~~
37
41
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:
41
45
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
46
47
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
50
51
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.
52
55
53
- $ uglifyjs --help
56
+ Now you can execute the ``uglifyjs `` command that lives in the ``node_modules ``
57
+ directory:
54
58
55
- $ ./app/Resources/node_modules/.bin/uglifyjs --help
59
+ .. code-block :: bash
60
+
61
+ $ " ./app/Resources/node_modules/.bin/uglifyjs" --help
56
62
57
63
Configure the ``uglifyjs2 `` Filter
58
64
----------------------------------
@@ -96,8 +102,7 @@ your JavaScripts:
96
102
.. note ::
97
103
98
104
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:
101
106
102
107
.. code-block :: bash
103
108
@@ -154,8 +159,8 @@ can configure its location using the ``node`` key:
154
159
Minify your Assets
155
160
------------------
156
161
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 :
159
164
160
165
.. configuration-block ::
161
166
@@ -178,8 +183,7 @@ your assets are a part of the view layer, this work is done in your templates:
178
183
179
184
The above example assumes that you have a bundle called AppBundle and your
180
185
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.
183
187
184
188
With the addition of the ``uglifyjs2 `` filter to the asset tags above, you
185
189
should now see minified JavaScripts coming over the wire much faster.
@@ -216,12 +220,9 @@ and :ref:`dump your assetic assets <cookbook-assetic-dump-prod>`.
216
220
217
221
.. tip ::
218
222
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.
225
226
226
227
Install, Configure and Use UglifyCSS
227
228
------------------------------------
@@ -231,8 +232,14 @@ the node package is installed:
231
232
232
233
.. code-block :: bash
233
234
235
+ # global installation
234
236
$ npm install -g uglifycss
235
237
238
+ # local installation
239
+ $ cd /path/to/your/symfony/project
240
+ $ mkdir app/Resources/node_modules
241
+ $ npm install uglifycss --prefix app/Resources
242
+
236
243
Next, add the configuration for this filter:
237
244
238
245
.. configuration-block ::
0 commit comments