Skip to content

Commit

Permalink
Merge pull request #4 from IngwiePhoenix/2.x
Browse files Browse the repository at this point in the history
Added ability for user to pass options via query parameter.
  • Loading branch information
bazilio91 committed May 12, 2015
2 parents 843f258 + dd77fc2 commit 270200e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var ejs = require('ejs'),
uglify = require('uglify-js');
uglify = require('uglify-js'),
utils = require("loader-utils");


module.exports = function (source) {
this.cacheable && this.cacheable();
var template = ejs.compile(source, {
client: true,
filename: '.'
});
var opts = utils.parseQuery(this.query);
opts.client = true;
opts.filename = this.resourcePath;
var template = ejs.compile(source, opts);

var ast = uglify.parser.parse(template.toString());

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ejs-compiled-loader",
"version": "2.0.0",
"version": "2.0.1",
"description": "EJS webpack loader (without frontend dependencies)",
"main": "index.js",
"scripts": {
Expand All @@ -24,6 +24,7 @@
"homepage": "https://github.com/bazilio91/ejs-compiled-loader",
"dependencies": {
"ejs": "^2.0.0",
"loader-utils": "^0.2.7",
"uglify-js": "~1.3.4"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion test/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
var tpl = require("./template.ejs");
console.log(tpl({noun: "World"}));
console.log(tpl({noun: "World"}));

var tpl2 = require("!!../?delimiter=?!./template2.ejs");
console.log( tpl2({hobbies: ["food", "code"]}).trimRight() );
3 changes: 3 additions & 0 deletions test/template2.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<? for(var key in hobbies) { var hobby = hobbies[key]; -?>
I like <?=hobby?>.
<? } ?>

0 comments on commit 270200e

Please sign in to comment.