【问题标题】:How do I include a JS file from a node_module in my view in Roots?如何在 Roots 的视图中包含来自 node_module 的 JS 文件?
【发布时间】:2017-01-15 20:35:49
【问题描述】:

我正在使用根 (http://roots.cx),我想在我的页面中包含来自 node_module 的库。我有npm install foo,图书馆在磁盘上。

我尝试将foo 添加到 app.coffee 中的extensions 并重新启动观察程序,但它呈现的路径是浏览器无法解析的 node_modules 文件夹。

extensions: [
    js_pipeline(files: 'node_modules/foo/lib/foo.js', 'assets/js/*.coffee'),
    css_pipeline(files: 'assets/css/*.styl')
  ]

在页面源代码中我得到了

<script src='node_modules/foo/lib/foo.js'></script>

从节点模块中包含库的正确方法是什么?

【问题讨论】:

    标签: javascript node.js roots-toolkit


    【解决方案1】:

    试试这个./,因为它只是一个文件而不是一个模块,像这样:

    extensions: [
        js_pipeline(files: './node_modules/foo/lib/foo.js', 'assets/js/*.coffee'),
        css_pipeline(files: 'assets/css/*.styl')
      ]
    

    否则尝试从node_modules 中提取或复制文件并将其放在单独的文件夹中

    【讨论】:

    • 没有变化 :( 我也启用了禁用缓存。
    猜你喜欢
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    相关资源
    最近更新 更多