从角度构建中删除代码

时间:2018-01-02 01:44:11

标签: javascript angular webpack preprocessor

我想知道如何提高angular2 +开发的效率。 目前,我有一份登记表。 此注册表单模型在开发期间填充了实际数据,并在构建之前手动删除。

没有办法告诉编译器'嘿,如果你在prod模式编译,请忽略这个!某种预处理器代码,如伪代码:

let rdata = {id:null, pass:null}
@@ignoreprod_start
  rdata.id = 2766;
  rdata.pass = "@(F-§44$A_NG%%p";
@@ignoreprod_end

1 个答案:

答案 0 :(得分:1)

我在Angular 4和5中工作过,我们有angular-cli.json,这个文件有apps.environments属性,你可以在其中相应地指定编译器。附加我的文件只是为了参考,这只是一个指针而不是一个完整的答案,你需要亲自看看你能做什么,但请问我有什么说明,这个文件environment.prod.ts和environment.ts在环境中定义文件夹,它取决于您使用的角度版本



{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "dncockpit"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.scss",
        "../node_modules/datatables.net-dt/css/jquery.dataTables.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/datatables.net/js/jquery.dataTables.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}