nativescript-hook-env-files

0.1.1 • Public • Published

nativescript-hook-env-files

A nativescript hook to replace file according to NODE_ENV value. Inspired by nativescript-hook-debug-production

Example

Project directory structure

app
├ env.development.json # {"production": false}
├ env.production.json  # {"production": true}
├ main.ts
├ ...

In your app code

const env = require('./env.json');

console.log(env.production); // 'true' if tns build or run with NODE_ENV=production, otherwise 'false'.

Webpack+Angular support

Add hostReplacementPaths option to NativescriptAngularCompilerPlugin in your webpack.config.js.

// utility method for getting replacement targets.
const { getReplacementPaths } = require('nativescript-hook-env-files/webpack');
new nsWebpack.NativeScriptAngularCompilerPlugin({
    entryModule: resolve(appPath, "app.module#AppModule"),
    tsConfigPath: join(__dirname, "tsconfig.esm.json"),
    skipCodeGeneration: !aot,
    platformOptions: {
        platform,
        platforms,
    },
    hostReplacementPaths: getReplacementPaths(appFullPath, process.env.NODE_ENV || 'development'), // add this line
}),

Readme

Keywords

none

Package Sidebar

Install

npm i nativescript-hook-env-files

Weekly Downloads

1

Version

0.1.1

License

none

Unpacked Size

4.4 kB

Total Files

7

Last publish

Collaborators

  • dobbydog