javascript - using definePlugin to pass constants to dependent packages -
i have 3 projects configured way:
- main app
- module a
- 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
Post a Comment