M
M
Makito2016-02-29 12:02:47
JavaScript
Makito, 2016-02-29 12:02:47

Webpack, how to import handlebars template not from entry point?

Good afternoon everyone.
There is the following structure (simplified):
src
- scripts
- templates
In scripts there are app.js and test.js files (app.js is the entry point for webpack)
app.js:

import Test from './test';

export default new Test();

test.js:
import tpl from '../templates/test.hbs';

export default class {
    constructor() {
        var body = document.querySelector('body');
        body.textContent = tpl({
            name: 'world'
        });
    }
}

There is test.hbs in the templates folder:
Hello {{name}}!
So if you import the hbs template directly into app.js, then webpack collects everything fine, but if through test.js it swears:
ERROR in ./src/templates/test.hbs
Module not found: Error : Cannot resolve module
What am I doing wrong?
Everything seems to be logical.

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