CodeSandbox 和 Angular Material 13
CodeSandbox and Angular Material 13
我正在尝试使用 CodeSandbox(并通过扩展 CLI)获得一个使用最新 (13.x) 版本的 Angular Material 实例。我收到可怕的“无法找到 angular material 核心主题”错误。请注意,我已尝试通过通常的路线导入
angular-cli.json:
"styles": ["./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"],
styles.css:
@import "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css";
@import "~@angular/material/prebuilt-themes/deeppurple-amber.css";
请注意,第一种方法不会“失败”,但对主题化没有任何帮助。第二种方法产生不同的错误:
postcss-import: /src/@angular/material/prebuilt-themes/indigo-pink.css:1:1: Unknown word
示例项目位于 https://codesandbox.io/s/idle-test-r3rqp3。任何提示或指示表示赞赏。
乔·艾伦
配置文件应在 angular 13 中调用 angular.json
。这是设置了 angular 13 和 material 的 stackblitz:https://stackblitz.com/edit/angular-ivy-w8wwx5?file=angular.json
这是配置文件:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/demo",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": [
"src/styles.css",
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.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": "demo:build"
},
"configurations": {
"production": {
"browserTarget": "demo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demo: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",
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
],
"scripts": [],
"assets": ["src/favicon.ico", "src/assets"]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"defaultProject": "demo"
}
我正在尝试使用 CodeSandbox(并通过扩展 CLI)获得一个使用最新 (13.x) 版本的 Angular Material 实例。我收到可怕的“无法找到 angular material 核心主题”错误。请注意,我已尝试通过通常的路线导入
angular-cli.json:
"styles": ["./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"],
styles.css:
@import "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"; @import "~@angular/material/prebuilt-themes/deeppurple-amber.css";
请注意,第一种方法不会“失败”,但对主题化没有任何帮助。第二种方法产生不同的错误:
postcss-import: /src/@angular/material/prebuilt-themes/indigo-pink.css:1:1: Unknown word
示例项目位于 https://codesandbox.io/s/idle-test-r3rqp3。任何提示或指示表示赞赏。
乔·艾伦
配置文件应在 angular 13 中调用 angular.json
。这是设置了 angular 13 和 material 的 stackblitz:https://stackblitz.com/edit/angular-ivy-w8wwx5?file=angular.json
这是配置文件:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"demo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/demo",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": [
"src/styles.css",
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.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": "demo:build"
},
"configurations": {
"production": {
"browserTarget": "demo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "demo: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",
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
],
"scripts": [],
"assets": ["src/favicon.ico", "src/assets"]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"defaultProject": "demo"
}