1

我想Handlebars在我的 CRA 项目中导入一个文件作为模板。

这是我目前的设置,改编自React-App- Rewired won't add Babel Plugin , handlebars-loader , and customize-cra

配置覆盖.js

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

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

module.exports = override(
    addHandleBarsLoader
);

在第三行我得到TypeError: template is not a function

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

安慰:

/static/media/test.a9cd7544.handlebars

包.json

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

我究竟做错了什么?

4

0 回答 0