angular - 错误 ReferenceError:particleJS 未定义 ~ Angular Universal + Webpack
问题描述
在我的 Angular 组件中,有完美工作的particle.js,在客户端使用 .js 渲染时效果很好ng serve
。但是,当将它与 Angular Universal for Server-Side Rendering (SSR) 结合使用时,我得到了错误ERROR ReferenceError: particlesJS is not defined
。我曾尝试使用 webpack 将其列入白名单,但没有奏效,webpack 的代码如下:
config.externals = nodeExternals({
// The whitelisted ones will be included in the bundle.
whitelist: [/^ng-circle-progress/, /^ng2-tel-input/, /^particles.js/]
});
其他 2 个软件包的错误消失了,但这个并不想消失。
我的后端使用NestJS,并尝试过applyDomino
,但也没有帮助,代码如下:
import { AngularUniversalModule, applyDomino } from '@nestjs/ng-universal';
import { join } from 'path';
import { Module } from '@nestjs/common';
// Get working directory of client bundle.
const BROWSER_DIR = join(
process.cwd(),
'functions',
'dist',
'apps',
'ditectrev-browser'
); // Use when testing locally without Firebase Cloud Functions solely on NestJS.
// const BROWSER_DIR = join(process.cwd(), 'dist/apps/ditectrev-browser'); // Use when deploying to & testing with Firebase Cloud Functions.
applyDomino(global, join(BROWSER_DIR, 'index.html'));
@Module({
imports: [
AngularUniversalModule.forRoot({
bundle: require('./../functions/dist/apps/ditectrev-server/main'), // Bundle is created dynamically during build process.
liveReload: true,
viewsPath: BROWSER_DIR
})
]
})
export class AppModule {}
有趣的是,即使我收到错误,页面也会在服务器端正确呈现!它不会破裂。单独使用 Cloud Functions for Firebase(本地和部署)进行渲染时,也会出现同样的错误。
注意:该主题无助于为我的问题particles.js 找到答案,并且未定义窗口
解决方案
推荐阅读
- javascript - 如何等到设置 cookie?
- eclipse - 在运行时配置 Xtext 生成器
- c# - 遵循开闭原则的灵活类设计
- java - Oracle JDK 到 OpenJDK
- c# - Tuple.Create :方法的类型参数不能从用法中推断出来
- android - Retrofit2:是否可以在类中隐藏定义为静态的 API url?
- botframework - BotFramework - Bot Emulator 中没有录制图标
- css - CSS 选择器 :last-child 和 :not
- raspbian - 授予对通过 fstab 和 x-systemd.automount 挂载的 smb 共享的非 sudo 写访问权限
- unity3d - 字体看起来方形而不是字母统一 5.6