Веб-пакет "Отказался от применения стиля из leaflet.css" - PullRequest
0 голосов
/ 21 сентября 2019

Я использую угловой стартер ngX-Rocket.Я хочу включить эту библиотеку карт листовок в свой проект: https://github.com/Asymmetrik/ngx-leaflet

Я включил файл в свой index.html

<link rel="stylesheet" type="text/css" href="./node_modules/leaflet/dist/leaflet.css" />

В консоли появляется следующая ошибка:

Refused to apply style from 'http://localhost:4200/node_modules/leaflet/dist/leaflet.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Я заметил, что нет файла webpack.config.js, поэтому я создал его и вставил:

module.exports = {
    "module" : {
        loaders: [
            { test: /\.css$/, loaders: [ 'style-loader', 'css-loader' ] }

        ]    
    }
};

Я также вставил свой angular.json:

{
  "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "myproject": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/favicon.ico",
              "src/apple-touch-icon.png",
              "src/robots.txt",
              "src/manifest.json",
              "src/assets"
            ],
            "styles": [
              "src/main.scss",
              "node_modules/leaflet/dist/leaflet.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ],
              "serviceWorker": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "ci": {
              "progress": false
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "hmr": true,
            "hmrWarning": false,
            "browserTarget": "myproject:build"
          },
          "configurations": {
            "production": {
              "hmr": false,
              "browserTarget": "myproject:build:production"
            },
            "ci": {
              "progress": false
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "myproject:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "scripts": [],
            "styles": [
              "src/main.scss",
              "node_modules/leaflet/dist/leaflet.css"
            ],
            "assets": [
              "src/favicon.ico",
              "src/apple-touch-icon.png",
              "src/robots.txt",
              "src/manifest.json",
              "src/assets"
            ]
          },
          "configurations": {
            "ci": {
              "progress": false,
              "watch": false
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "myproject-e2e": {
      "root": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "myproject:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "myproject"
}

Хотя я все еще вижу ошибку в веб-консоли.Что мне нужно сделать, чтобы избавиться от этой ошибки?

Я включил файл в свой index.html

1 Ответ

0 голосов
/ 21 сентября 2019

Попробуйте добавить его в файл angular.json в разделе styles

"styles": [
    "styles.css",
    "./node_modules/leaflet/dist/leaflet.css"
],

Более подробную информацию можно найти здесь: Добавление CSS и JavaScript в Angular CLI Project

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...