|
4 | 4 | * see: http://github.com/jrburke/requirejs for details
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -/*jslint plusplus: false, nomen: false, regexp: false, strict: false */ |
| 7 | +/*jslint plusplus: false, nomen: false, regexp: false */ |
8 | 8 | /*global define: false */
|
9 | 9 |
|
10 | 10 | define([ 'lang', 'logger', 'env!env/optimize', 'env!env/file', 'parse',
|
@@ -148,11 +148,37 @@ function (lang, logger, envOptimize, file, parse,
|
148 | 148 | var parts = (config.optimize + "").split('.'),
|
149 | 149 | optimizerName = parts[0],
|
150 | 150 | keepLines = parts[1] === 'keepLines',
|
151 |
| - licenseContents = '', |
152 |
| - fileContents, optFunc, match, comment; |
| 151 | + fileContents; |
153 | 152 |
|
154 | 153 | fileContents = file.readFile(fileName);
|
155 | 154 |
|
| 155 | + fileContents = optimize.js(fileName, fileContents, optimizerName, |
| 156 | + keepLines, config, pluginCollector); |
| 157 | + |
| 158 | + file.saveUtf8File(outFileName, fileContents); |
| 159 | + }, |
| 160 | + |
| 161 | + /** |
| 162 | + * Optimizes a file that contains JavaScript content. Optionally collects |
| 163 | + * plugin resources mentioned in a file, and then passes the content |
| 164 | + * through an minifier if one is specified via config.optimize. |
| 165 | + * |
| 166 | + * @param {String} fileName the name of the file that matches the |
| 167 | + * fileContents. |
| 168 | + * @param {String} fileContents the string of JS to optimize. |
| 169 | + * @param {String} [optimizerName] optional name of the optimizer to |
| 170 | + * use. 'uglify' is default. |
| 171 | + * @param {Boolean} [keepLines] whether to keep line returns in the optimization. |
| 172 | + * @param {Object} [config] the build config object. |
| 173 | + * @param {Array} [pluginCollector] storage for any plugin resources |
| 174 | + * found. |
| 175 | + */ |
| 176 | + js: function (fileName, fileContents, optimizerName, keepLines, config, pluginCollector) { |
| 177 | + var licenseContents = '', |
| 178 | + optFunc, match, comment; |
| 179 | + |
| 180 | + config = config || {}; |
| 181 | + |
156 | 182 | //Apply pragmas/namespace renaming
|
157 | 183 | fileContents = pragma.process(fileName, fileContents, config, 'OnSave', pluginCollector);
|
158 | 184 |
|
@@ -182,7 +208,7 @@ function (lang, logger, envOptimize, file, parse,
|
182 | 208 | config[optimizerName]);
|
183 | 209 | }
|
184 | 210 |
|
185 |
| - file.saveUtf8File(outFileName, fileContents); |
| 211 | + return fileContents; |
186 | 212 | },
|
187 | 213 |
|
188 | 214 | /**
|
|
0 commit comments