-
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.
Merge pull request #5 from jantimon/2.x
Add support for `webpack --optimize-minimize` and use relative filepaths
- Loading branch information
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; | ||
}; |