rollup.js中的rxjs不会导出"主题"

Geo*_*rds 6 javascript rxjs rollupjs angular

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

错误:node_modules\rxjs\Subject.js不会导出"Subject"

这是我的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()
  ]
}
Run Code Online (Sandbox Code Playgroud)

为什么会这样,我跟着angular2食谱指南?

Ric*_*ris 10

您需要使用namedExportsrollup-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' ]
  }
})
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的评论.这会在删除namedExport之前出现"重复导出'主题'"错误.然后它工作.对我来说至少. (3认同)