Vue.js, global variables and TypeScript
Published at January 15, 2019 · 2 min read
It’s pretty easy to pass some environment variable to Vue.js application using webpack.DefinePlugin. You just need to have something like a sample below in your webpack.config.js
:
var webpack = require('webpack')
module.exports = {
// ...
plugins: [
// ...
new webpack.DefinePlugin({
'BUILD': JSON.stringify(0.0.1')
})
]
}
It’s a common way to pass some environment variable into your JavaScript application. Technically, webpack.DefinePlugin
injects a global variable into your JavaScript application. You may need it for some feature flags or some global configuration.