Skip to content

Instantly share code, notes, and snippets.

@jackmahoney
Last active April 5, 2019 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jackmahoney/87018e5955124e33fe789536e17df7e1 to your computer and use it in GitHub Desktop.
Save jackmahoney/87018e5955124e33fe789536e17df7e1 to your computer and use it in GitHub Desktop.
Vuepress Markdown Variable substitution
// inside config.js extend webpack so that `__var_name__` is replaced with value of `config[var_name]`
// relies on npm install string-replace-loader
{
configureWebpack(config) {
config.resolve.alias["@"] = path.join(__dirname, "/theme");
config.resolve.alias["~"] = path.join(__dirname, "/public");
if (process.env.NODE_ENV === "production") {
const mappings = Object.keys(config).map(key => {
return { search: `__${key}__`, replace: config[key] }
})
console.log(mappings)
config.module.rules.push({
test: /\.*/,
loader: "string-replace-loader",
options: {
multiple: mappings
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment