节点模块问题

时间:2017-08-29 16:22:19

标签: node.js npm browserify

我根本不是Node的专家,但我在学习!我最近遇到了一个我希望包含在项目中的模块"响应式背景" https://www.npmjs.com/package/responsive-backgrounds

所有版本都安装了npm install --save-dev responsive-backgrounds,看起来很好(即我可以在我的minifed和uglified distributon JS中看到ResponsiveBackgrounds)。在我的主要JS文件中,我有:

require("responsive-backgrounds");
options = {
    lazy: true,
    transition: 0.5
};
new ResponsiveBackground("#featuredimage", options);

然而,当我运行我的浏览器和uglified JS时,我得到Uncaught ReferenceError: ResponsiveBackground is not defined。我错过了一些关键的东西吗我确定还有其他库可以完成相同的工作,甚至更好,但更多的是要了解如何正确包含节点模块。

1 个答案:

答案 0 :(得分:0)

需要将变量设置为您尝试导入的模块 试试:

  let ResponsiveBackground = require("responsive-backgrounds");
    options = {
        lazy: true,
        transition: 0.5
    };
    new ResponsiveBackground("#featuredimage", options);