|
1 | 1 | var ejs = require('ejs'), |
2 | 2 | uglify = require('uglify-js'), |
3 | | - utils = require("loader-utils"); |
| 3 | + utils = require('loader-utils'), |
| 4 | + path = require('path'); |
4 | 5 |
|
5 | 6 |
|
6 | 7 | module.exports = function (source) { |
7 | 8 | this.cacheable && this.cacheable(); |
8 | 9 | var opts = utils.parseQuery(this.query); |
9 | 10 | opts.client = true; |
10 | | - opts.filename = this.resourcePath; |
| 11 | + |
| 12 | + // Skip compile debug for production when running with |
| 13 | + // webpack --optimize-minimize |
| 14 | + if (this.minimize && opts.compileDebug === undefined) { |
| 15 | + opts.compileDebug = false; |
| 16 | + } |
| 17 | + |
| 18 | + // Use filenames relative to the context (in most cases the project root) |
| 19 | + opts.filename = path.relative(this.context, this.resourcePath); |
| 20 | + |
11 | 21 | var template = ejs.compile(source, opts); |
12 | 22 |
|
13 | | - var ast = uglify.parser.parse(template.toString()); |
| 23 | + // Beautify javascript code |
| 24 | + if (!this.minimize && opts.beautify !== false) { |
| 25 | + var ast = uglify.parser.parse(template.toString()); |
| 26 | + template = uglify.uglify.gen_code(ast, {beautify: true}); |
| 27 | + } |
14 | 28 |
|
15 | | - return 'module.exports = ' + uglify.uglify.gen_code(ast, {beautify: true}); |
| 29 | + return 'module.exports = ' + template; |
16 | 30 | }; |
0 commit comments