status-web-archive/packages/react-chat-example/webpack.config.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-09-29 12:49:38 +00:00
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const webpack = require('webpack');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
2021-09-24 11:36:26 +00:00
2021-09-29 12:49:38 +00:00
module.exports = env => {
2022-01-05 12:51:12 +00:00
const environment = env.ENV || 'development';
const communityKey = env.COMMUNITY_KEY || '';
2021-09-24 11:36:26 +00:00
2021-09-29 12:49:38 +00:00
return {
entry: './src/index.tsx',
output: {
filename: 'index.[fullhash].js',
path: path.join(__dirname, 'dist'),
publicPath: '/',
},
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
fallback: {
buffer: require.resolve('buffer/'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
2022-01-11 08:27:32 +00:00
assert: require.resolve('assert/'),
2021-11-26 11:24:37 +00:00
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
zlib: require.resolve('browserify-zlib')
2021-09-29 12:49:38 +00:00
},
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'esbuild-loader',
exclude: /node_modules/,
options: {
loader: 'tsx',
2022-02-04 09:01:49 +00:00
target: 'es2020',
2021-09-29 12:49:38 +00:00
},
2021-09-24 11:36:26 +00:00
},
2021-09-29 12:49:38 +00:00
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'source-map-loader',
2021-09-24 11:36:26 +00:00
},
2021-09-29 12:49:38 +00:00
{
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf|ico)$/,
use: ['file-loader'],
2021-09-24 11:36:26 +00:00
},
2021-09-29 12:49:38 +00:00
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
2021-09-24 11:36:26 +00:00
},
2021-09-29 12:49:38 +00:00
],
},
optimization: {
minimizer: [
new ESBuildMinifyPlugin({
2022-02-04 09:01:49 +00:00
target: 'es2020',
2021-09-29 12:49:38 +00:00
}),
],
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new webpack.DefinePlugin({
'process.env.ENV': JSON.stringify(environment),
2022-01-05 12:51:12 +00:00
'process.env.COMMUNITY_KEY': JSON.stringify(communityKey),
2021-09-29 12:49:38 +00:00
}),
new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
}),
],
devServer: {
historyApiFallback: true,
host: '0.0.0.0',
stats: 'errors-only',
overlay: true,
hot: true,
},
stats: 'minimal',
};
};