Angular-添加-js fle获取未捕获的SyntaxError:意外的字符串

时间:2018-11-16 19:48:25

标签: javascript angular sass

我有一个angular 6应用程序,我正在尝试设置自己的样式库... 这是 angular.json 文件的外观:

"root": "",
  "sourceRoot": "src",
  "projectType": "application",
  "prefix": "app",
  "schematics": {
    "@schematics/angular:component": {
      "styleext": "scss"
    }
  },
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/adm-auth-frontend",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "node_modules/bootstrap/scss/bootstrap.scss",
          "src/styles.scss"
        ],
        "scripts": [
          "src/assets/scripts/index.js"
        ]
      },
      "configurations": {

如您所见,该项目是使用sass设置的,并且运行良好。 问题是我需要一些脚本文件,我已经在脚本部分中添加了这些文件,但是当我运行execute ng serve 时,出现以下错误,现在仍然可以使用:(

See error

我尝试使用 ng弹出将其添加到webpack配置文件中。.

The 'eject' command has been temporarily disabled, as it is not yet compatible with the new angular.json format. The new configuration format provides further flexibility to modify the configuration of your workspace without ejecting. Ejection will be re-enabled in a future release of the CLI.If you need to eject today, use CLI 1.7 to eject your project.

index.js 文件:

@import './spec/settings/index.scss';
@import './spec/tools/index.scss';
@import 'bootstrap/scss/bootstrap.scss';
@import './spec/index.scss';
@import './vendor/index.scss';

如何添加这些.js文件?

1 个答案:

答案 0 :(得分:0)

在angular.json文件上添加的Angular脚本仅运行一次 当angular接管应用程序时,它将一次读取这些脚本并加载 因此,建议不要使用带有尖角的js文件,除非更改为HTML手动重新触发,否则它们将无法再次运行。

改用ng-bootstrap或 临时解决方案是在index.html上添加手动标签, 这行得通,但还不够好。