【问题标题】:How to ignore modules from the karma config file with browserify如何使用 browserify 忽略 karma 配置文件中的模块
【发布时间】:2015-06-24 10:52:02
【问题描述】:

我正在尝试使用需要 jsdom 的 testdom 测试 React.js。 我在 browserify 中使用业力。 jsdom 不能被浏览器化,所以我想忽略它。

我遇到的问题是尝试从 karma.config.js 文件中执行此操作。

browserify: {
    debug: true,
    transform: [
      "babelify"
    ],
    ignore: [] or {} or...???
  },

【问题讨论】:

  • []{} 都试过了吗?他们没有工作吗?

标签: testing reactjs karma-runner browserify


【解决方案1】:

感谢@marcel 的回答。 我不确定为什么它在我的情况下不起作用(使用excludeignore) 但我设法从中得到了我需要的东西......

browserify: { debug: true, transform: [ "babelify" ], configure: function(bundle) { bundle.on('prebundle', function() { bundle.ignore('jsdom'); }); } }

您可能已经猜到了,为“prebundle”注册一个回调,您可以在其中配置捆绑包。来自 karma-browserify 文档:https://github.com/Nikku/karma-browserify#additional-bundle-configuration

不是最干净的,但它有效。我已经放弃了对 testdom/jsdom 的需求。

【讨论】:

  • 太棒了。谢谢你。我想知道为什么ignore: ['things'] 不起作用。 . .
【解决方案2】:

试试这个:

browserify: {
    debug: true,
    transform: [
        "babelify"
    ],
    exclude: [
        "jsdom"
    ]
},

exclude 将省略输出包中的文件。你也可以试试ignore: 用空存根替换文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 2016-01-02
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多