diff --git a/LICENSE b/LICENSE index 21e4ca3..7bc1643 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 011425c..fa2b382 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 } @@ -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); - + ```
@@ -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: [ { @@ -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: [ //... @@ -227,7 +228,7 @@ In order to deactivate image processing define the `attributes` option as an emp ```javascript module.exports = { //... - + module: { loaders: [ { @@ -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: [ { @@ -301,6 +302,32 @@ module.exports = {
+## 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. + +
+ +```javascript +module.exports = { + //... + + module: { + loaders: [ + { + test: /\.html$/, + loader: "handlebars-template-loader", + query: { + runtimePath: 'handlebars/runtime' + } + } + ] + } +}; +``` + +
+ ## Compilation options ##
@@ -410,7 +437,7 @@ module.exports = { { test: /\.hbs/, loader: "handlebars-template-loader" }, } }, - + macros: { copyright: function () { return "'

Copyright FakeCorp 2014 - 2015

'"; @@ -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: { // ... @@ -481,7 +508,7 @@ module.exports = { { test: /\.html$/, loader: "handlebars-template-loader" }, } }, - + macros: { header: function (size, content) { return "'" + content + "'"; diff --git a/index.js b/index.js index 937a11d..fcd772c 100644 --- a/index.js +++ b/index.js @@ -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); @@ -53,6 +54,10 @@ module.exports = function(content) { if (query.parseDynamicRoutes !== undefined) { parseDynamicRoutes = !!query.parseDynamicRoutes; } + + if (query.runtimePath) { + runtimePath = query.runtimePath; + } } // Include additional macros @@ -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 + ');'); }; diff --git a/package.json b/package.json index 184c7f7..b28f6ec 100644 --- a/package.json +++ b/package.json @@ -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", @@ -24,6 +24,9 @@ }, { "name": "Matt Thompson (whatknight)" + }, + { + "name": "Harry Wolff (hswolff)" } ], "repository": {