A
A
Alexey Yakovlev2020-09-02 17:07:42
Handlebars
Alexey Yakovlev, 2020-09-02 17:07:42

Webpack does not add hbs code to compiled html file, what should I do?

webpack:

module.exports = {
    //......
    plugins: [
        new HTMLWebpackPlugin({
            hash: false,
            inject: false,
            template: './src/views/index.hbs',
            minify: {
                collapseWhitespace: isProd
            },
        })
    ],
    module: {
        rules: [
            {
                test: /\.hbs$/,
                use: ['handlebars-template-loader']
            }
        ],
    },
};


server:
//....
const app = express();

const hbs = exphbs.create({
    defaultLayout: 'main',
    extname: 'hbs'
});

app.engine('hbs', hbs.engine);
app.set('view engine', 'hbs');
app.set('views', './src/views');

app.use(express.static(path.join(__dirname + '/dist/')));
app.use('/', homeRoute);
//....


main.hbs:
{{> head }}
<body>
    {{> header }}
    {{> up }}
    {{> preolaider }}
    {{{ body }}}
    {{> footer }}
    {{> down }}
</body>
</html>


Compiles to an html file that main.hbs doesn't see

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question