- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Angular 10.2.1 应用程序使用自定义 webpack 构建器在我的 .scss 文件中支持 PostCSS,这在 SPA 模式下工作得很好。
angular.json
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
webpack.config.js
let plugins = [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
loader: 'postcss-loader',
options: {
ident: 'postcss',
syntax: 'postcss-scss',
plugins: () => plugins
}
}
]
}
};
我决定根据官方文档使用 ng add @nguniversal/express-engine
添加 SSR 支持,但是当我尝试提供 SSR 版本时,出现错误:
ERROR in Module build failed (from ./node_modules/@angular-devkit/build-angular/node_modules/sass-loader/dist/cjs.js):
SassError: expected ";".
╷
90 │ @apply border-pink-200 !important;
│ ^
╵
src/app/app.component.scss 90:32 root stylesheet
这很有意义,因为 ng add @nguniversal/express-engine
添加到 angular.json 的 SSR 人工制品不使用我的自定义 webpack 配置。我已经查看了 @nguniversal/builders
和 @angular-builders
但找不到有关如何为 nguniversal 加载自定义 webpack 文件的任何信息。
这是我的完整 angular.json
文件:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"hp24-frontend": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "hp24",
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
"outputPath": "dist/hp24-frontend/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/assets"
],
"styles": [
"src/styles/styles.scss"
],
"scripts": [],
"stylePreprocessorOptions": {
"includePaths": [
"src/styles"
]
}
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
"browserTarget": "hp24-frontend:build"
},
"configurations": {
"production": {
"browserTarget": "hp24-frontend:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "hp24-frontend:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles/variables/_colors.scss",
"src/styles/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json",
"tsconfig.server.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "hp24-frontend:serve"
},
"configurations": {
"production": {
"devServerTarget": "hp24-frontend:serve:production"
}
}
},
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/hp24-frontend/server",
"main": "server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
"production": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"sourceMap": false,
"optimization": true
}
}
},
"serve-ssr": {
"builder": "@nguniversal/builders:ssr-dev-server",
"options": {
"browserTarget": "hp24-frontend:build",
"serverTarget": "hp24-frontend:server"
},
"configurations": {
"production": {
"browserTarget": "hp24-frontend:build:production",
"serverTarget": "hp24-frontend:server:production"
}
}
},
"prerender": {
"builder": "@nguniversal/builders:prerender",
"options": {
"browserTarget": "hp24-frontend:build:production",
"serverTarget": "hp24-frontend:server:production",
"routes": [
"/"
]
},
"configurations": {
"production": {}
}
}
}
}},
"defaultProject": "hp24-frontend"
}
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
],
"resolveJsonModule": true,
"esModuleInterop": true,
"types": ["googlemaps"]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"debug": true
}
}
如有任何帮助,我们将不胜感激。 :)
最佳答案
解决方案是在 nguniversal 添加的服务器工件中将 @angular-devkit/build-angular:server
替换为 @angular-builders/custom-webpack:server
angular.json
像这样:
"server": {
"builder": "@angular-builders/custom-webpack:server",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
"outputPath": "dist/hp24-frontend/server",
"main": "server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
"production": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"sourceMap": false,
"optimization": true
}
}
},
这似乎也修复了 serve-ssr
和 prerender
人工制品,因为它们在内部调用 server
。所以现在我可以将所有 nguniversal npm 脚本与我自己的自定义 webpack 配置一起使用。
关于带有 @nguniversal 的 Angular SSR 和用于 PostCSS 支持的自定义 webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64666158/
Angular CLI:8.0.1节点:12.3.1操作系统:win32 x64 Angular :8.0.0 运行时ng add @nguniversal/express-engine --clie
我按照 Angular 文档 here 将服务器端渲染添加到我的 Angular 项目中. 我发现运行静态预渲染 npm run build:prerender 和 npm run serve:pre
问题 我一直在尝试通过运行“ng add @nguniversal/express-engine@next”为我的 Angular 项目添加 seo 功能,但不断收到错误 An unhandled e
我正在学习 angular universal .在这一步: ng add @nguniversal/express-engine --clientProject angular.io-example
我的 Angular 10.2.1 应用程序使用自定义 webpack 构建器在我的 .scss 文件中支持 PostCSS,这在 SPA 模式下工作得很好。 angular.json
我的 Angular 10.2.1 应用程序使用自定义 webpack 构建器在我的 .scss 文件中支持 PostCSS,这在 SPA 模式下工作得很好。 angular.json
我对 Angular 官方文档有点困惑。我试图学习如何使用 Angular universal 来构建一些东西。但是我在文档中看到了这个命令: ng add @nguniversal/express-
尝试运行 @angular/fire在 Angular 11 和 @nguniversal/express-engine 上(SSR)。 初始化时AngularFireModule在 app.modu
第一个问题 目标 我正在尝试使用 ng add @nguniversal/express-engine --clientProject [name] 将 SSR 添加到我的 Angular 项目中(这
我正在使用@nguniversal/express-engine 以 Angular 进行服务器端渲染。当我运行 $ nmp build:ssr 或 $ npm run dev:ssr 我得到这个错误
我是一名优秀的程序员,十分优秀!