【问题标题】:Angular 5 CLI import/require custom node moduleAngular 5 CLI 导入/需要自定义节点模块
【发布时间】:2018-09-16 17:51:41
【问题描述】:

我的node_modules 目录中有一个节点模块。但是,我不知道如何使用它。结构如下:

node_modules
|- ...
|- foo-bar
| |- dist
| |  |- css
| |     - css files here
| |  |- js
| |     - js files here
| |  |- foo-images
| |     - image files here
| |  |- index.js
| |- index.js
| |- package.json
|- ...

index.js 里面有这个:

require('./dist/js/foo');
module.exports = 'foo';

所以我的问题是如何使用它?在我的app.component.ts 中,我尝试将以下代码放在顶部:

import { foo } from './foo-bar';

但是foo 上的大括号之间有一个错误,表示它不知道那是什么。当我尝试require('foo') 时,我收到一条错误消息,说它不知道require 是什么(我安装了Express)。

如何使用节点模块中的 CSS 和 JavaScript 函数?我是 Angular 5 的新手,所以我并不完全熟悉它的工作原理。任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: node.js angular webstorm angular5 node-modules


    【解决方案1】:

    Angular 是前端框架,NodeJS 是服务器端,因此您必须在后端服务器上运行任何节点模块...当我想使用 image magick 在本地调整文件图像大小然后上传到时,我遇到了类似的问题服务器。使用 express 将数据从服务器获取到前端,然后您可以将数据放入 '{{}}' :)

    【讨论】:

    • 非常感谢!这真的很有帮助。
    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 2017-01-21
    • 1970-01-01
    • 2022-10-16
    • 2018-08-02
    • 2018-08-25
    • 1970-01-01
    • 2017-05-19
    相关资源
    最近更新 更多