使生成服务<script> type =“ module”

时间:2019-11-04 12:12:30

标签: angular

嗨,我运行ng serve来在electron.net中运行角度应用程序

但仍然存在问题:我通过使用ng buildng build --watch

来解决它

问题是:由于以下原因,使用ng serve应用程序不起作用 生成<script src= "..." >而没有<script src="..." type="module">

所以我尝试使用ng build并正确生成所有东西

但是使用ng build --watch会生成与ng serve相同的脚本

因此,当我通过添加ng build --watch更改从type="module"生成的文件时 一切正常

我从This Github issue知道,角度8默认情况下会这样做 但是他们说它只会在默认情况下为serve生成es2015

这里的问题是type =“ module”属于es2015,未生成

所以简而言之:问题是如何配置Angular-Cli ng以生成 当我将type="module"ng serve

一起使用时,脚本与ng build --watch一起使用

我的tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "module": "esnext",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2015",
      "dom"
    ]
  }
}

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ElectronAngularNet": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "progress": true,
            "extractCss": true,
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": ["src/assets"],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": [],
            "fileReplacements": [
              {
                "replace": "src/app/electronConfig/electron.service.ts",
                "with": "src/app/electronConfig/electron.replace.service.ts"
              }
            ]
          },
          "configurations": {
            "development": {
              "fileReplacements": [
                {
                  "replace": "src/app/electronConfig/electron.service.ts",
                  "with": "src/app/electronConfig/electron.replace.service.ts"
                }
              ]
            },
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                },
                {
                  "replace": "src/app/electronConfig/electron.service.ts",
                  "with": "src/app/electronConfig/electron.replace.service.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ElectronAngularNet:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ElectronAngularNet:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ElectronAngularNet:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": ["styles.css"],
            "scripts": [],
            "assets": ["src/assets"]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist-server",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.server.json"
          },
          "configurations": {
            "dev": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": true
            },
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false
            }
          }
        }
      }
    },
    "ElectronAngularNet-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "ElectronAngularNet:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    }
  },
  "defaultProject": "ElectronAngularNet"
}

ng version

Angular CLI: 8.3.14
Node: 10.16.1
OS: win32 x64
Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.803.14
@angular-devkit/core         8.3.14
@angular-devkit/schematics   8.3.14
@schematics/angular          8.3.14
@schematics/update           0.803.14
rxjs                         6.4.0


谢谢。

0 个答案:

没有答案