Skip to content

Loads and compiles handlebars-files to html and returns it as a string

Notifications You must be signed in to change notification settings

sueddeutsche/handlebars-render-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handlebars Render Loader

npm install handlebars-render-loader --save-dev

Loads and compiles handlebars-files to html and returns it as a string. Additionally resolves and register all missing partials as a webpack-url (relative or absolute from a module). A missing partial must either be

  • a relative path, starting with "./" or "../" or
  • an absolute path within a module, which has no starting "/". i.e. {{> szig-frontend-toolkit/components/..}}

Usage

in your webpack config add the loader i.e.

var HTMLExtractPlugin = new ExtractTextPlugin("html", "index.html");

var webpackConfig = {

    module: {
        loaders: [
            {
                loader: `file-loader?name=[name].html!extract-loader!html-loader!handlebars-render-loader`,
                test: /\.hbs$/
            }
        ]
    },

    handlebarsRenderLoader: {

        // debug registered partials
        debug: false,

        // data used to render hbs template
        data: require("./data/project.json"),

        // partials are usually resolved via webpack.
        // You may specify a map of partial aliases.
        // This is usually necessary when you have dynamic partials.
        partialAliases: {
            "partial-one": require.resolve("path/to/partial-one"),
            "partial-two": require.resolve("path/to/partial-two")
        },

        // register custom helpers with file globs
        // The file name is used as helper id. The .helper postfix will be removed.
        helpers: [
            path.join(process.cwd(), "app", "helpers", "*.helper.js")
        ],

        // hooks
        onBeforeCompile: function (Handlebars, templateContent) {},
    }
};

About

Loads and compiles handlebars-files to html and returns it as a string

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published