我有一个正常工作的Babel加载器。
{ test: /\.jsx?$/, loader: 'babel', query: babelSettings, exclude: /node_modules/ },
但现在我想要一个 CoffeeScript 加载器,但我希望通过 Babel 管道传递它以获得花哨的 HMR 功能。
{ test: /\.coffee$/, loader: 'babel!coffee', query: babelSettings, exclude: /node_modules/ },
然而,这样做行不通,会导致以下错误。
错误:无法同时在加载器列表中定义“query”和多个加载器
有什么办法只为loader链中的Babel部分定义查询吗? 查询是一个复杂的对象,我不认为我能编码它。
var babelSettings = { stage: 0 };
if (process.env.NODE_ENV !== 'production') {
babelSettings.plugins = ['react-transform'];
babelSettings.extra = {
'react-transform': {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module']
}, {
transform: 'react-transform-catch-errors',
imports: ['react', 'redbox-react']
}]
// redbox-react is breaking the line numbers :-(
// you might want to disable it
}
};
}