Y
Y
yeco2021-12-13 10:02:20
Vue.js
yeco, 2021-12-13 10:02:20

How to create a variable directly accessible in index.html?

Hello, I can read variables through htmlWebpackPlugin.options but how to create my own variable
for example as Value in documentation https://cli.vuejs.org/ru/guide/html-and-static-ass...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Barabanov, 2021-12-13
@yeco

If you are using Vue-cli then just add to vue.config.js :

module.exports = {
...
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        VAR_NAME: VAR_VALUE,
      }),
    ],
  },
...
}

In the template you can then use like <%= VAR_NAME %>. In JS, of course, also as VAR_NAME.
If just webpack - before just add a section to plugins in webpack.config.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question