Skip to content

Instantly share code, notes, and snippets.

@pauloreis7
Last active August 7, 2021 16:38
Show Gist options
  • Save pauloreis7/0550397a58d6b3f5601b1eded4f3c27e to your computer and use it in GitHub Desktop.
Save pauloreis7/0550397a58d6b3f5601b1eded4f3c27e to your computer and use it in GitHub Desktop.
Webpack config
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
const isDevelopment = process.env.NODE_ENV !== 'production'
module.exports = {
mode: isDevelopment ? 'development' : 'production',
devtool: isDevelopment ? 'eval-source-map' : 'source-map',
entry: path.resolve(__dirname, 'src', 'index.tsx'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
devServer: {
contentBase: path.resolve(__dirname, 'public'),
hot: true,
},
plugins: [
isDevelopment && new ReactRefreshWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'public', 'index.html')
})
].filter(Boolean),
module: {
rules: [
{
test: /\.(j|t)sx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [
isDevelopment && require.resolve('react-refresh/babel')
].filter(Boolean)
}
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment