react webpack code example
Example 1: jsx babel webpack
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
Example 2: reactjs and webpack tutorial
npm i webpack webpack-cli --save-dev
Example 3: add webpack to react project
{ "presets": [ "@babel/preset-env", "@babel/preset-react" ]}
Example 4: reactjs and webpack tutorial
"scripts": {
"build": "webpack --mode production"
}
Example 5: add webpack to react project
module.exports = { entry: './src/index.js', module: { rules: [ { test: /\.(js|jsx)$/, exclude: /node_modules/, use: ['babel-loader'] } ] }, resolve: { extensions: ['*', '.js', '.jsx'] }, output: { path: __dirname + '/dist', publicPath: '/', filename: 'bundle.js' }, devServer: { contentBase: './dist' }};
Example 6: add webpack to react project tutorial
npm i webpack webpack-cli webpack-dev-server --save-dev