Search code examples
mustachewebpack-2preprocessor

Replace mustache tags in JS file and output the replaced JS


I have a file config.js with some Mustache templates inside, something like this:

export default {
  VAR1: {{var1}},
  VAR2: '{{var2}}'
};

I want to process that file before anything else so it would go through the Webpack pipeline (Babel, etc) as this (supposing that var1 is set to 42 and var2 is set to hello):

export default {
  VAR1: 42,
  VAR2: 'hello'
};

I’ve tried to use mustache-loader but it seems to create a function representing the compiled template file, instead of the result file, no matter the setting I use.

Is there any way (loader, whatever) that would make this work?


Solution

  • For those curious, I’ve solved the problem with render-template-loader instead, chained with extract-loader.