-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
webpack --optimize-minimize
Use relative paths
- Loading branch information
Jan Nicklas
committed
Jun 15, 2015
1 parent
270200e
commit 6efcc2e
Showing
2 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
var ejs = require('ejs'), | ||
uglify = require('uglify-js'), | ||
utils = require("loader-utils"); | ||
utils = require('loader-utils'), | ||
path = require('path'); | ||
|
||
|
||
module.exports = function (source) { | ||
this.cacheable && this.cacheable(); | ||
var opts = utils.parseQuery(this.query); | ||
opts.client = true; | ||
opts.filename = this.resourcePath; | ||
|
||
// Skip compile debug for production when running with | ||
// webpack --optimize-minimize | ||
if (this.minimize && opts.compileDebug === undefined) { | ||
opts.compileDebug = false; | ||
} | ||
|
||
// Use filenames relative to the context (in most cases the project root) | ||
opts.filename = path.relative(this.context, this.resourcePath); | ||
|
||
var template = ejs.compile(source, opts); | ||
|
||
var ast = uglify.parser.parse(template.toString()); | ||
// Beautify javascript code | ||
if (!this.minimize && opts.beautify !== false) { | ||
var ast = uglify.parser.parse(template.toString()); | ||
template = uglify.uglify.gen_code(ast, {beautify: true}); | ||
} | ||
|
||
return 'module.exports = ' + uglify.uglify.gen_code(ast, {beautify: true}); | ||
return 'module.exports = ' + template; | ||
}; |