Last active
April 5, 2019 05:02
-
-
Save jackmahoney/87018e5955124e33fe789536e17df7e1 to your computer and use it in GitHub Desktop.
Vuepress Markdown Variable substitution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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