NativeScript / nativescript-dev-webpack

A package to help with webpacking NativeScript apps.
Apache License 2.0
97 stars 49 forks source link

webpack is not picking up the CLI environment variables #1143

Closed hraynaud closed 4 years ago

hraynaud commented 4 years ago

configs.zip Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug I'm building a nativescript-vue app I'm unable to read environment variables passed from the command line when using the nativescript CLI. Inside of webpack.config.js I expect to be able to do a console.log(env) and see the variables I've passed to the tns run command printed out.

To Reproduce tns run ios --device 'iPhone 11' --env.server_url=localhost:3000

Expected behavior // webpack.config.js

module.exports = env => {
    console.dir(env); // {  server_url: 'localhost:3000' }
}

Sample project

Additional context Ultimately my goal is to be able to pass the variables to DefinePlugin so that In can access them in Vue application. Note -- I understand that webpack.DefinePlugin will simply do a textual replace of the value provide.

hraynaud commented 4 years ago

I attached the webpack.config.js and package.json as a zip file

hraynaud commented 4 years ago

Actually this was my mistake. I was using console.dir() instead of console.log() to verify that the env vars were present. console.log() works fine and the vars are in fact picked up. Didn't realize the console.dir() only takes one argument whereas console.log() takes any number.