Ensure that you install the correct npm dependencies (babel decided to split itself into a bunch of packages, something to do with "peer dependencies"):
npm install webpack webpack-node-externals babel-core babel-loader babel-preset-react babel-preset-latest --save
webpack.config.js
:
module.exports = {
context: __dirname, // sets the relative dot (optional)
entry: "./index.jsx",
output: {
filename: "./index-transpiled.js"
},
module: {
loaders: [{
test: /\.jsx$/,
loader: "babel?presets[]=react,presets[]=latest" // avoid .babelrc
}]
}, // may need libraryTarget: umd if exporting as a module
externals: [require("webpack-node-externals")()], // probably not required
devtool: "inline-source-map"
};
webpack-node-externals
is a function that scans your node_modules
and ensures that they aren't transpiled and bundled along with your front-end code, though it ensures the bundle retains reference to them. This helps with faster transpilation, since you're not re-encoding libraries.