Skip to content

Commit 5b5899c

Browse files
committed
Merge pull request #5 from jantimon/2.x
Add support for `webpack --optimize-minimize` and use relative filepaths
2 parents 270200e + 6efcc2e commit 5b5899c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ejs-compiled-loader for webpack
22

3-
EJS loader for [webpack](http://webpack.github.io/). Uses [ejs](https://github.com/tj/ejs) function to compile templates.
3+
EJS loader for [webpack](http://webpack.github.io/). Uses [ejs](https://github.com/mde/ejs) function to compile templates.
44

5-
To use EJS by tj use 1.x branch and 1.x.x versions.
5+
To use [EJS by tj](https://github.com/tj/ejs) use 1.x branch and 1.x.x versions.
66

77
## Installation
88

index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
var ejs = require('ejs'),
22
uglify = require('uglify-js'),
3-
utils = require("loader-utils");
3+
utils = require('loader-utils'),
4+
path = require('path');
45

56

67
module.exports = function (source) {
78
this.cacheable && this.cacheable();
89
var opts = utils.parseQuery(this.query);
910
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+
1121
var template = ejs.compile(source, opts);
1222

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+
}
1428

15-
return 'module.exports = ' + uglify.uglify.gen_code(ast, {beautify: true});
29+
return 'module.exports = ' + template;
1630
};

0 commit comments

Comments
 (0)