How to use handlebars-loader in a Create React App project?

680 views Asked by At

I'd like to import a Handlebars file as a template in my CRA project.

This is my current setup, adapted from React-App- Rewired won't add Babel Plugin, handlebars-loader, and customize-cra

config-overrides.js

const { override } = require('customize-cra');

const addHandleBarsLoader = config => {
    config.module.rules.push(
        { test: /\.handlebars$/, loader: "handlebars-loader" }
    );
    return config;
}

module.exports = override(
    addHandleBarsLoader
);

on the 3rd line here i get TypeError: template is not a function

const template = require("./test.handlebars");
console.log(template);
const htmlString = template(data);

console:

/static/media/test.a9cd7544.handlebars

package.json

  "scripts": {
    "start": "react-app-rewired start",
...

what am i doing wrong?

0

There are 0 answers