使用 WebPack 编译的 Handlebars 很慢

Handlebars compiling with WebPack is slow

我正在做一个有很多不同模板的项目,目前大约有 67 个。每次我更改 1 个文件时,Webpack 都会开始重新编译每个 handlebars 模板,这使得它非常慢。

我想知道是否有减少工作量/优化速度的方法。

我在 Webpack 中的 Handlebars 工作流程如下所示:

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.

试试https://github.com/trivago/parallel-webpack

我会将这些数组拆分成不同的配置,以便并行 webpack 可以同时 运行 它们

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