Handlebars compiling with WebPack is slow

时间:2017-10-12 09:44:51

标签: webpack handlebars.js webpack-2 webpack-plugin

I'm working on a project which has A LOT of different templates, around ~ 67 at the moment. Every time I make a change in 1 file, Webpack starts recompiling every handlebars template, which makes it very slow.

I'm wondering if there's a way to reduce the workload / optimize the speed.

My Handlebars workflow in Webpack looks like this:

var Handlebars = require('handlebars-webpack-plugin');
....
....
new Handlebars({
        entry: path.join(process.cwd(), "src", "layouts", "default.hbs"),
        output: path.join(process.cwd(), "dist", "form-template.html"),
        data: {title: 'Form template', properties: {partial: 'form-template/index'}},
        partials: [
            path.join(process.cwd(), "src", "partials", "**/*.hbs")
        ]
    }),
new Handlebars({
        entry: path.join(process.cwd(), "src", "layouts", "default.hbs"),
        output: path.join(process.cwd(), "dist", "homepage.html"),
        data: {title: 'Homepage', properties: {partial: 'homepage/index'}},
        partials: [
            path.join(process.cwd(), "src", "partials", "**/*.hbs")
        ]
    }),
new Handlebars({
        entry: path.join(process.cwd(), "src", "layouts", "default.hbs"),
        output: path.join(process.cwd(), "dist", "404.html"),
        data: {title: '404 error', properties: {partial: '404/index'}},
        partials: [
            path.join(process.cwd(), "src", "partials", "**/*.hbs")
        ]
    }),
...
... etc.

1 个答案:

答案 0 :(得分:2)

尝试给https://github.com/trivago/parallel-webpack一个。

我将这些数组拆分为不同的配置,因此并行webpack可以同时运行它们

还有https://www.npmjs.com/package/happypack可以解决这个问题