找不到node_modules路径

时间:2017-12-09 23:35:03

标签: html angularjs node.js node-modules

我的项目结构如下:

enter image description here

在我的index.html中,我试图访问node_modules中的特定js。

我试过这些:

<script src="./node_modules/ng-currency/dist/ng-currency.js"></script>

<script src="../node_modules/ng-currency/dist/ng-currency.js"></script>

<script src="../../node_modules/ng-currency/dist/ng-currency.js"></script>

没有工作,只有当我将node_modules文件夹复制到公共文件夹时才有效,有更好的方法吗?

2 个答案:

答案 0 :(得分:0)

在客户端js文件中引用的每个javascript文件都不需要在公共文件夹中!

答案 1 :(得分:0)

您可以将其导出为app.js文件中的静态资源,然后在html中使用它,就像您现在所做的那样。如果您正在使用express,那么它非常简单。

app.js:

app.use('/scripts', express.static(path.join(__dirname, '/node_modules/ng-currency/dist/')));

HTML:

<script src="/scripts/ng-currency.js" type="text/javascript"></script>