【发布时间】:2017-06-15 20:49:24
【问题描述】:
我正在尝试在我的 Angular 1 应用程序中加载一个非 Angular 库。
index.html 有以下脚本:
<head>
<script type="text/javascript" src="../node_modules/@mylib/index.js" charset="utf-8"></script>
<script type="text/javascript"src="../bower_components/myOtherlib/index.js"charset="utf-8"></script>
</head>
我的目录结构是:
MyApp
- src
- app
- index.js
- index.html
- node_modules
- bower_components
- package.json
- bower.json
- test
- gulpfile.js
我可以从 index.html 访问 bower_components,但不能访问 node_modules。 所以我可以加载 myOtherlib/index.js 但不能加载 @mylib/index.js
当我加载 index.html 时出现错误:
GET http://localhost:3000/node_modules/@mylib/index.js 404(未找到)
我正在使用 IntelliJ。
如果有人能帮我解决这个问题,那将会很有帮助。感谢您的时间和帮助。
【问题讨论】:
-
节点模块通常是服务器端...究竟你想从浏览器中访问什么?
-
你试过运行
npm install吗? -
我有一个库,我想在 index.html 中访问它并在前端使用库中的类。
-
您只需将所述文件移动到浏览器可用的位置。您不需要捆绑器,gulp 可用于将此文件移动到您的构建目录中。
-
我的观点仍然成立;如果这是一个打算在浏览器中使用的库,它应该已经将自身复制到浏览器可访问的目录中。在不知道库是什么的情况下,不清楚为什么不是这种情况,甚至还不清楚哪些文件需要移动到哪里。
标签: javascript angularjs node-modules