我首先使用我这样安装的 commonjs 模块进行了测试:
npm install the-module;
然后我创建main.js
了看起来像这样的东西:
var module = require('the-module');
module.doStuff();
然后main.js
用 webpack 编译成bundle.js
,加载到浏览器中,就搞定了。
现在我想the-module
在 Angular 4 服务中使用。我应该如何导入它?
我还发现了这篇关于如何创建 Angular 2 组件库的文章。好奇 Angular 将导入的所有 commonjs 模块是否都需要这组步骤,或者是否有更直接的方法?
相关概念
写完这篇文章: