在我的项目中,我使用gulp来运行任务,用webpack编译js模块,它使用babel加载器来转换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一起工作? 感谢。