Skip to content

Commit

Permalink
Merge branch 'mongodb-js-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Antico committed Jun 23, 2017
2 parents 7362e37 + bb4da9d commit 8f6db14
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Emmanuel Antico
Copyright (c) 2014 - 2017 Emmanuel Antico

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
51 changes: 39 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A Handlebars template loader for Webpack
- [Options](#options)
- [Prepending filename comment](#prepending-filename-comment)
- [Images](#images)
- [Runtime path](#runtime-path)
- [Compilation options](#compilation-options)
- [Macros](#macros)
- [require](#require)
Expand Down Expand Up @@ -52,13 +53,13 @@ npm install handlebars-template-loader
```javascript
module.exports = {
//...

module: {
loaders: [
{ test: /\.hbs/, loader: "handlebars-template-loader" }
]
},

node: {
fs: "empty" // avoids error messages
}
Expand Down Expand Up @@ -134,13 +135,13 @@ require("./helpers.js");
```javascript
// Get Handlebars instance
var Handlebars = require('handlebars-template-loader/runtime');

// Require partial
var partial = require('path/to/my/_partial.hbs');

// Register partial
Handlebars.registerPartial('my_partial_name', partial);

```

<br/>
Expand All @@ -160,7 +161,7 @@ When debugging a large single page app with the DevTools, it's often hard to fin
```javascript
module.exports = {
//...

module: {
loaders: [
{
Expand All @@ -186,7 +187,7 @@ In order to load images you must install either the `file-loader` or the `url-lo
```javascript
module.exports = {
//...

module: {
loaders: [
//...
Expand Down Expand Up @@ -227,7 +228,7 @@ In order to deactivate image processing define the `attributes` option as an emp
```javascript
module.exports = {
//...

module: {
loaders: [
{
Expand All @@ -251,7 +252,7 @@ You could also add which attributes need to be processed in the form of pairs *t
```javascript
module.exports = {
//...

module: {
loaders: [
{
Expand Down Expand Up @@ -301,6 +302,32 @@ module.exports = {

<br/>

## Runtime path ##

If you have a custom location for your Handlebars runtime module then you can set that in your `query` object via the `runtimePath` property. This is the path to the Handlebars runtime that every `.hbs` file will require and use. By default this loader looks up the absolute path to the `handlebars/runtime` in your `node_modules` folder. Changing this property is useful if you are doing somethign non-standard with your Handlebar templates, for example setting an alias for the `handlebars/runtime` path.

<br/>

```javascript
module.exports = {
//...

module: {
loaders: [
{
test: /\.html$/,
loader: "handlebars-template-loader",
query: {
runtimePath: 'handlebars/runtime'
}
}
]
}
};
```

<br />

## Compilation options ##

<br/>
Expand Down Expand Up @@ -410,7 +437,7 @@ module.exports = {
{ test: /\.hbs/, loader: "handlebars-template-loader" },
}
},

macros: {
copyright: function () {
return "'<p>Copyright FakeCorp 2014 - 2015</p>'";
Expand Down Expand Up @@ -444,7 +471,7 @@ You can disable macros if you are a bit unsure about their usage or just simply
```javascript
module.exports = {
// ...

module: {
loaders: {
// ...
Expand Down Expand Up @@ -481,7 +508,7 @@ module.exports = {
{ test: /\.html$/, loader: "handlebars-template-loader" },
}
},

macros: {
header: function (size, content) {
return "'<h" + size + ">" + content + "</h" + size + ">'";
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = function(content) {
var root,
parseMacros = true,
attributes = ['img:src'],
parseDynamicRoutes = false;
parseDynamicRoutes = false,
runtimePath = require.resolve('handlebars/runtime').replace(/\\/g, '/');

// Parse arguments
var query = this.query instanceof Object ? this.query : loaderUtils.parseQuery(this.query);
Expand All @@ -53,6 +54,10 @@ module.exports = function(content) {
if (query.parseDynamicRoutes !== undefined) {
parseDynamicRoutes = !!query.parseDynamicRoutes;
}

if (query.runtimePath) {
runtimePath = query.runtimePath;
}
}

// Include additional macros
Expand Down Expand Up @@ -88,7 +93,7 @@ module.exports = function(content) {
// Resolve attributes
source = attributesContext.resolveAttributes(source);

callback(null, 'var Handlebars = require(\'' + require.resolve('handlebars/runtime').replace(/\\/g, '/') + '\');\n' +
callback(null, 'var Handlebars = require(\'' + runtimePath + '\');\n' +
'module.exports = (Handlebars[\'default\'] || Handlebars).template(' + source + ');');
};

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "handlebars-template-loader",
"version": "0.7.1",
"version": "0.8.0",
"description": "A Handlebars template loader for Webpack",
"main": "index.js",
"homepage": "https://github.com/emaphp/handlebars-template-loader",
Expand All @@ -24,6 +24,9 @@
},
{
"name": "Matt Thompson (whatknight)"
},
{
"name": "Harry Wolff (hswolff)"
}
],
"repository": {
Expand Down

0 comments on commit 8f6db14

Please sign in to comment.