2

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

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

我在 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.
4

1 回答 1

3

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

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

还有https://www.npmjs.com/package/happypack可能会成功

于 2017-10-18T16:59:31.277 回答