NativeScript Hook Env Files
根据 NODE_ENV 值替换文件的 NativeScript Hook。灵感来源于 nativescript-hook-debug-production
npm i --save nativescript-hook-env-files

NativeScript Hook Env Files

根据 NODE_ENV 值替换文件的 NativeScript Hook。灵感来源于 nativescript-hook-debug-production

示例

项目目录结构

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

在你的应用代码中

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

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

Webpack+Angular 支持

hostReplacementPaths 选项添加到你的 webpack.config.js 中的 NativescriptAngularCompilerPlugin

// 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
}),