在我的项目中,我使用 gulp 运行任务,使用 webpack 编译 js 模块,使用 babel loader 来转换 react 和 ES6。现在我想添加继电器转换。我按照以下说明进行操作:https ://facebook.github.io/relay/docs/guides-babel-plugin.html#advanced-usage但它们似乎不正确。
我不得不做一些小的逆向工程,并制作了以下 gulp 任务:
gulp.task('js', () => {
// Compile babel (react)
gulp.src(paths.js)
.pipe(er(webpack({
module: {
plugins: [
new require('webpack/lib/ProvidePlugin')({
React: "React",
Relay: 'Relay'
})
],
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel',
query: {
presets: ['es2015', 'stage-0', 'react'],
plugins: [require('babel-relay-plugin')(require(paths.db_schema).data)]
}
}
]
},
output: {
filename: paths.js_output
}
})))
.pipe(gulp.dest(paths.dist));
});
现在我得到每个处理的文件这样的错误:
ERROR in (filename)
Module build failed: TypeError: Falsy value found in plugins
at d:\Node\organize.me\node_modules\babel-core\lib\transformation\file\options\option-manager.js:187:15
at Array.map (native)
at Function.normalisePlugins (d:\Node\organize.me\node_modules\babel-core\lib\transformation\file\options\option-manager.js:182:20)
at OptionManager.mergeOptions (d:\Node\organize.me\node_modules\babel-core\lib\transformation\file\options\option-manager.js:298:36)
at OptionManager.init (d:\Node\organize.me\node_modules\babel-core\lib\transformation\file\options\option-manager.js:481:10)
at File.initOptions (d:\Node\organize.me\node_modules\babel-core\lib\transformation\file\index.js:211:75)
at new File (d:\Node\organize.me\node_modules\babel-core\lib\transformation\file\index.js:129:22)
at Pipeline.transform (d:\Node\organize.me\node_modules\babel-core\lib\transformation\pipeline.js:48:16)
at transpile (d:\Node\organize.me\node_modules\babel-loader\index.js:14:22)
at Object.module.exports (d:\Node\organize.me\node_modules\babel-loader\index.js:88:12)
@ multi main
我做了更多的逆向工程,我发现插件中的数组只是[ null ]
当我用
plugins: [new (require('babel-relay-plugin')(require(paths.db_schema).data))()]
我收到错误
TypeError: Cannot read property 'Plugin' of undefined
那么我怎样才能让 gulp、webpack、babel 和 relay 一起工作呢?谢谢。