Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import * as Handlebars from "handlebars/runtime" to register custom helpers #1711

Closed
fdiluzio opened this issue Sep 8, 2020 · 2 comments
Closed

Comments

@fdiluzio
Copy link

fdiluzio commented Sep 8, 2020

refers to: #1553

I need to import Handlebars differently when using custom helpers.
I'm using webpack.

The fiddle works as expected:
https://jsfiddle.net/5jpc9obu/

My handlebars 4.7.6 package.json is:
"browser": {
".": "./dist/cjs/handlebars.js",
"./runtime": "./dist/cjs/handlebars.runtime.js"
},

I import Handlebars in a class like this when I register a helper. Otherwise the helper is missing.
import * as Handlebars from "handlebars/runtime";

However, my entry point js uses Handlebar.compile and that only works when I import like this:
import Handlebars from 'handlebars';

My distributed js file, however, remains the same size even with the two different imports.

@sophiebl
Copy link

Here is a work around solution for this with Object.assign():

import MainHandlebars from "handlebars";
import * as RuntimeHandlebars from "handlebars/runtime";
const Handlebars = Object.assign(MainHandlebars, RuntimeHandlebars);

@fdiluzio
Copy link
Author

fdiluzio commented Jan 30, 2021

Interesting. I'll have to consider that the next time I visit my code. But I don't think you should mix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants