broccoli-config-replace 不适用于给定的配置

broccoli-config-replace does not work with the configuration given

我尝试使用 broccoli-config-replace 失败。我想做的是替换 index.html 中的占位符,然后通过执行 broccoli serve

在浏览器中查看它

我 Brocfile.js 的有趣部分是这个:

var index_html = new ConfigReplace(app, './', {
    // A list of files to parse:
    files: [
        'index.html',
    ],
    configPath: 'replacements.json',
    outputPath: 'production/',
    patterns: [{
        match: /\{\{SRC_REQUIRE\}\}/g,
        replacement: function(config) { return config.SRC_REQUIRE; }
    }]
});

module.exports = index_html;

但是当我 运行 broccoli serve 我得到的是这个警告,将我的浏览器指向 localhost:4200:

什么也没有出现
$ broccoli serve

Serving on http://localhost:4200

Warning: failed to stat tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/tmp/config_replace-input_base_path-5qF5n457.tmp/1/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/yargs/node_modules/cliui/node_modules/center-align/node_modules/align-text/node_modules/kind-of/README.md
Segmentation fault: 11

不错的段错误吧?我想我写的不是那么好,但是文档非常缺乏。谁能建议我正确的配置来完成这个简单的任务?谢谢

我已经想出了如何获得我想要的东西,但我认为该插件仍需要一些开发。这是正确的配置:

var index_html = new ConfigReplace(appHtml, 'conf', {
    // A list of files to parse:
    files: [
        '/production/index.html'
    ],
    configPath: 'replacements.json',
    patterns: [{
        match: /\{\{SRC_REQUIRE\}\}/g,
        replacement: function(config) { return config.SRC_REQUIRE; }
    }]
});

我注意到的一些事实:

  • 配置节点必须是一个目录。不允许使用 Root,所以我不得不将我的 replacements.json 放在子文件夹中 (/conf)
  • outputPath选项好像没有考虑。我省略了它并在之前使用了 pickFile 以创建具有我想要的正确结构的树。然后我将树传递给 ConfigReplace(你在我上面粘贴的配置中看到的 appHtml
  • 缺乏文件是愉快地采用西兰花的坏朋友。不过我有信心。