javascript - using definePlugin to pass constants to dependent packages -


i have 3 projects configured way:

  1. main app
    1. module a
    2. module b

on main app, i'm using defineplugin pass dependent modules api url, this:

//webpack-1 loaders:[{     test:/\.jsx?$/,     exclude: /(node_modules)/,     loader: "babel",     query: {         presets:["es2015","stage-2","react"]     } }], plugins:[new webpack.defineplugin({"api_url":"http://www.google.com"})] 

then, within modules & b, use constant this

axios.get(`${api_url}/getproducts`).then(response=>console.log(response)); 

i've migrated webpack v2 code config file changes to:

//webpack-2 rules:[{     test:/\.jsx?$/,     exclude: /(node_modules)/,     loader: "babel",     options: {         presets:["es2015","stage-2","react"]     } }], plugins:[new webpack.defineplugin({"api_url":"http://www.google.com"})] 

but when try use api_url on dependent modules following error:

referenceerror:api_url not defined 

what doing wrong? else need configure?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -