Created
March 15, 2019 14:38
-
-
Save anthonny/54bf484b3633d934dfe17d036c9f8b58 to your computer and use it in GitHub Desktop.
Use dotenv with NativeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
const dotenv = require("dotenv"); | |
// ... | |
console.log(`Bundling application for entryPath ${entryPath}...`); | |
dotenv.config() | |
const isUppercase = key => key.toUpperCase() === key; | |
const envKeys = Object.keys(env); | |
let dotEnvValues = envKeys | |
.filter(isUppercase) | |
.reduce((memo, key) => { | |
return {...memo, [key]: JSON.stringify(env[key])}; | |
}, {}) | |
const dotEnvkeys = Object.keys(process.env); | |
dotEnvValues = dotEnvkeys | |
.filter(isUppercase) | |
.reduce((memo, key) => { | |
if (memo[key]) { | |
return memo; | |
} | |
return {...memo, [key]: dotEnvValues[key] || JSON.stringify(process.env[key])}; | |
}, {...dotEnvValues}) | |
const definitiveEnv = { | |
"global.TNS_WEBPACK": "true", | |
"TNS_ENV": JSON.stringify(mode), | |
...dotEnvValues | |
} | |
const config = { | |
// ... | |
plugins: [ | |
// ... Vue Loader plugin omitted | |
// make sure to include the plugin! | |
new VueLoaderPlugin(), | |
// Define useful constants like TNS_WEBPACK | |
new webpack.DefinePlugin(definitiveEnv), | |
// ... | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for ns8 you can do
(webpack.config.js)