首页 > 解决方案 > 如何以角度添加额外的加载器?

问题描述

我是 Angular 的新手,我尝试将 .js 文件导入到我的 app.component.ts,该文件是 npm 包的一部分

import { Component } from '@angular/core';

import { ListenerScroll } from '../utils/listener-scroll';

@Component({...});

但我有这个错误:

Module parse failed: Unexpected token (8:28)
File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
 * ./node_modules/@ngtools/webpack/src/ivy/index.js
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| 
| export class ListenerScroll {
>       static listenerScrollAdded = false;
|       static listenerScroll = [];
| 

我知道静态属性并非在所有浏览器中都可用,因此我必须“转换” .js 文件,在 webpack 中您可以添加 babel 并将现代语言转换为浏览器可以读取的语言,如何在角度上做类似的事情?

谢谢您的帮助!:)

标签: javascriptangularwebpack

解决方案


推荐阅读