Socket
Socket
Sign inDemoInstall

@gzaripov/injectify

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @gzaripov/injectify

Add require helper to handlebars for browserify


Version published
Maintainers
1
Install size
6.39 MB
Created

Readme

Source

Injectify Build Status npm downloads

Inspired by hbsfy and based on it source code.

Transform handlebars AST and add support of require helper for browserify/webpack automatic injection;

Install

npm install --save-dev injectify

Use with browserify

Use it as Browserify transform module with -t:

browserify -t injectify main.js > bundle.js

If you prefer gulp:

var gulp = require("gulp"),
    browserify = require("browserify"),
    source = require("vinyl-source-stream"),
    
gulp.task('js', function () {
    var bundleStream = browserify('./src/main.js')
        .transform(require("injectify"))
        .bundle();

    return bundleStream
        .pipe(source('main.js'))
        .pipe(gulp.dest('dist'));
});

Use with webpack

Configure webpack

{
    "module": {
        "loaders": [
            {"test": /\.hbs/, "loader": "injectify"}
        ]
    }
}

Load helper

In file ./src/main.js require injectify require helper:

require("injectify/require");

Now you can use require helper in your templates:

Simple require some module with string export: 

{{require "../string-module"}}

Pass require result as param to another helper: 

{{formatUser (require "../user-module")}}

Pass require result as hash param to another helper: 

{{formatUser user=(require "../user-module")}}

require helper works like original browserify. You can require modules relative to template file or node_modules directory

Relative require {{require "../utils/strange-module"}} 

or globally defined {{require "my-utils"}}

Examples of usage

  • Include helper - allow include templates like partials, but with browserify
  • View helper - allow render marionette view direct to template

Changelog

v2.2.0

  • Handlebars 4.0 support

FAQs

Last updated on 01 Nov 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc