【问题标题】:Use npm module for front end dependencies failed对前端依赖项使用 npm 模块失败
【发布时间】:2016-06-13 17:16:04
【问题描述】:

我以为我可以做 npm 而不是 bower,我所做的是做 npm install angular --save,然后像这样包含它

<script src="../node_modules/angular/angular.js"></script>

但路径似乎不正确。我创建了一个临时仓库来展示我的文件夹结构。

https://github.com/eldyvoon/temp/

【问题讨论】:

  • 我没有在您的仓库中看到 node_modules 文件夹。请确保您已成功设置NPM
  • @Vineet 尝试克隆并运行npm install。通常人们将 node_modules 文件夹放在 .gitignore 中。

标签: javascript node.js npm gulp


【解决方案1】:

为了使用 node_modules,您必须使用 browsersync 公开目录。

试试这个,像这样更改 gulfile.js 中的浏览器同步 gulp 任务:

gulp.task('browser-sync', function() {
    browserSync.init(null, {
        server: {
            baseDir: 'app',
            routes: {
                '/node_modules': './node_modules'
            }
        }
    });
});

在你的 index.html 中你的 jquery 导入是错误的,使用这个:

<script src="../node_modules/jquery/dist/jquery.min.js"></script>

希望对您有所帮助,如果您需要更多信息,请告诉我

【讨论】:

  • 您确定这是问题所在吗?即使我手动刷新它我仍然得到错误 angularjs 文件未加载
  • 我已经尝试过你的项目。你重启browsersync了吗?如果你愿意,我可以在 jour github 项目上创建一个拉取请求
  • 我在你的项目上创建了一个拉取请求
  • 谢谢!但 angularjs 仍然无法正常工作,我推了我的代码@rick
  • 依赖问题解决了吗?如果是这样,请创建另一个问题,以便我们查看它。也许给我答案:)
猜你喜欢
  • 1970-01-01
  • 2016-06-23
  • 1970-01-01
  • 2014-08-08
  • 1970-01-01
  • 2012-07-07
  • 2013-08-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多