使用webpack配置babel

时间:2017-04-27 01:08:38

标签: webpack babeljs

我正在尝试使用webpack配置babel。到目前为止,我已经看到了两条路,想知道它们之间的区别。

路径1 在webpack.config.js文件中包含以下内容

 loaders: [{
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
                presets: ['es2015']
            }
        }]
webpack.config.js中的

Path2 包括以下内容

 loaders: [{
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader'
        },

并在单独的.babelrc文件中包含以下内容

{
    "presets": [
        "es2015"
    ]       
}

两者之间有什么区别?首选方法是什么?

1 个答案:

答案 0 :(得分:1)

在webpack配置中定义加载器上的babel配置仅适用于webpack,而使用inp1 = Input((28,28)) inp2 = Input((28,28)) in1 = Reshape((1,28,28))(inp1) in2 = Reshape((1,28,28))(inp2) c = Concatenate(axis =1)([in1,in2]) #here, the lambda expression sums two MNIST images c = Lambda(lambda x: x[:,0]+x[:,1],output_shape=(28,28))(c) m = Model([inp1,inp2],c) res = m.predict([xTraining[:10],xTraining[10:20]]) print(res.shape) #if you plot the res, you will see the images superposed, which was the expected result. 将影响以任何方式使用babel的所有内容(例如babel-registerbabel-node

如果您只使用webpack,那么只要您需要不使用webpack的东西,例如服务器或您希望使用的功能的测试框架,它就没有区别在节点中尚未提供,您还需要为此配置babel。

通常首选使用.babelrc,因为您希望拥有一般的babel配置,如果您需要覆盖设置,您仍然可以在特定应用程序中执行此操作,例如在webpack配置中。

相关问题