将 reactjs 组件作为节点模块导出到 npm 时,我是包含 jsx 还是 js

When exporting reactjs components as node modules to npm, do I include jsx or js

我一直在创建一些 React.js 组件并将它们作为模块发布到 npm。

我正在使用以下 gulp 任务将我所有的 jsx 组件转换为 js,使用 gulp-react:

var react = require('gulp-react');

gulp.task('react', function () {    
  return gulp.src('./jsx/*.jsx')
    .pipe(react({
      harmony: true
    }))
    .pipe(gulp.dest('./js/'));
});

所以在我发布的模块中,js 和 jsx 文件夹中有组件。

我的问题是在我的 package.json 中将主文件指向哪个更好?

js

"main": "js/todo.js",

jsx

"main": "jsx/todo.jsx",

我假设如果我将它们指向 jsx,那么它们将需要安装 gulp-react,那么我会把它添加到 peerDependencies 中吗?

好问题,经典特例"do I include build artifacts in my repo?"。我倾向于指向 JS 文件,因为 package/dependencies 管理器的要点是,当你发布东西时,其他人应该能够立即安装并开始使用,而不必自己考虑依赖关系.例如:

我在命令行安装我的包:

$ npm install something

打开节点 repl 并且:

> var something = require('something');
undefined
> something.functionallity(1, 2, 3);
...whatever, but you wouldn't like an error now...

你的 .js,因为你可以在管道中添加更多内容,它会被覆盖