javascript - rollup.js 中的 rxjs 不导出“主题”

标签 javascript angular rxjs rollupjs

我正在尝试设置我的项目以使用汇总,作为 angular2 迁移到 AOT 编译的一部分,但是,我遇到了以下问题。

Error: 'Subject' is not exported by node_modules\rxjs\Subject.js

这是我的rollup.js 文件:

import rollup from 'rollup';
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs    from 'rollup-plugin-commonjs';
import uglify      from 'rollup-plugin-uglify'

export default {
  entry: 'client/main.js',
  dest: 'public/assets/js/build.js',
  sourceMap: false,
  format: 'iife',
  plugins: [
      nodeResolve({jsnext: true, module: true}),
      commonjs({
        include: 'node_modules/rxjs/**',
        include: 'node_modules/angular2-jwt/**',
      }),
      uglify()
  ]
}

为什么会这样,我已经按照 angular2 cookbook 指南做了?

最佳答案

您需要将 namedExports 选项与 rollup-plugin-commonjs 一起使用:https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports .

此外,您可能会发现 include: 'node_modules/**' 比单独的包更有用,否则您的依赖项的任何依赖项都将绕过插件(在上面的配置中,您有重复的 include 属性——也许这只是一个拼写错误?如果您需要传递多个值,请使用数组)。

commonjs({
  include: 'node_modules/**',
  namedExports: {
    'node_modules/rxjs/Subject.js': [ 'Subject' ]
  }
})

关于javascript - rollup.js 中的 rxjs 不导出“主题”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39955241/

相关文章:

angular - 如何创建具有延迟和限制尝试的 RXjs RetryWhen

javascript - RxJs - 创建 Observables 的 Observable 数组的正确模式/方法是什么?

javascript - 模糊验证的 jquery

javascript - google maps api v3 - 从外部点击打开信息窗口

javascript - Angular 2 使用 ngfor 获取 json 数据

javascript - 右侧面板内容的页面上的侧边栏菜单是否有 CSS 或 Jquery 术语

angular - 在 Angular 服务中通过 id 在 RxJS Subjects Map 中缓存状态

javascript - Angular 模板引用 : Bind height of one div to height of another

angular - 使用 RxJS(和 Angular)临时缓存来自参数化请求的 HTTP 响应

angular - 试图在 Angular 2 项目中将多个 observables 合并为一个