节点模块问题

Node Module Issue

我根本不是 Node 专家,但我正在学习!我最近遇到了一个我想包含在项目中的模块 "responsive-backgrounds" 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);

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

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

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