- 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/
很好,我在一台通过PM2执行的阿帕奇服务器上运行了一个带有ANGLE Universal的Web。。进行更改时,我会生成新版本的Web、将文件上传到主机并重新启动PM2任务。但当访问网络时,这些变化不
我在使用快速服务器构建和提供 Angular Universal 应用程序以获得良好的 SEO 方面遇到了挑战。 当我使用带有命令 "dev:ssr": "ng run motif:serve-ssr
我想在我的 nuxt 项目中使用一个 stencil 库。 我能够让它工作,但是当 vue 组件在服务器端呈现时,我只能让 stencil 的组件呈现在客户端。 我认为最大的问题是 defineCus
我想将我的sveltekit SSR应用托管到AWS服务(Amplify)。我们怎么能做到这一点呢?如果我们使用适配器静态,它是否会影响SSR?如果我们可以使用任何其他AWS服务来托管我们的svelt
我想为我的用户对我的应用进行 SSR。 但我的应用程序代码使用 useEffect 来检测用户屏幕宽度的大小,然后才呈现应用程序。 类似于: App.js // THE LAYOUT INITIA
我正在尝试制作一个 SSR react 应用程序,但无法将 Prop 从 express 传递到组件。 我在做什么错? server.js import AppPage2 from './src/pr
我使用 webpack 捆绑了我的 SSR 存储库(类似 inferno-react 的 lib)。它有 2 个路由文件,1 个用于服务器,1 个用于客户端,完全相同,但使用 require.ensu
当我用react做SSR时,发送给客户端的内容是如何构造的? 它是否等待异步操作完成? 是否等待状态树中的所有组件是否以某种方式保持稳定? 它会在某些生命周期方法中等待异步代码,例如用 await/a
我正在尝试创建一个 Angular 服务,组件可以使用该服务来观看窗口大小调整事件。经过多次尝试,我终于发现这个解决方案效果最好 https://stackoverflow.com/a/4383381
我正在重构一个大量使用 vue 组件的网络应用程序。 目前,vue 组件是使用 twig 模板语言在服务器端呈现的。组件作为静态 html 呈现给页面......没有使用 webpack 或 vue
我是 kibana 的新手,我想知道 kibana 如何在仪表板上生成可视化? 即 是否使用 SSR 生成图形/饼图等? 它是否使用 elastic-charts/charts.js/d3.js 等库
我的主代码 (app.component.html) 上没有任何会导致重新加载的更高级别的 NgIf。我正在使用 transferstate,因此在 SSR 设置公共(public) url 的答案后
我是 flutter 的新手,我想为我的 flutter Web 应用程序实现 SSR。 Flutter web 是否支持 SSR(服务器端渲染)? 我应该如何实现它? 最佳答案 尚未实现,但您可以在
我想知道是否有人可以向我指出如何为 vue SSR(服务器端渲染)设置包裹的资源或示例。 或者包裹不能使用Vue SSR? 最佳答案 应该像安装所需的各种库一样简单: # Yarn $ yarn ad
我使用 Angular SSR,当我刷新页面时,它首先进入登录页面,然后进入所需页面。 我还使用 cookie 来存储 token 。 canActivate( route: ActivatedRou
我在 SSR 上运行的异步管道有问题。没有错误,只有无限循环(似乎服务器正在等待 observable 被解析)。 我在用: @nestjs/ng-universal Angular 9 Fireba
以下内容适用于通过 NextJS 的 SSR。 我正在使用 React 的上下文来跟踪某些已安装组件的 ID。要点是 class Root extends React.Component { ge
我使用 React、react-router、@loadable/component 创建了一个项目。 现在我正在尝试将 SSR 添加到该项目中。我使用react-router进行了服务器端渲染。 然
我是 Angular ssr 的新手,您可以看到下面的代码 问题 如果我直接进入客户端路由,首先会显示 Rendered by server 但很快它就会重新渲染页面并显示: Rendered by
当窗口未定义时,我一直在尝试测试 else block 。当我使用 Next.js 时,窗口在服务器端渲染 (SSR) 期间将是未定义的。目前我找不到办法做到这一点。 非常感谢任何帮助。 我已经尝试在
我是一名优秀的程序员,十分优秀!