2021-08-06 12:50:36 +00:00
|
|
|
const path = require('path')
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
|
|
|
|
const webpack = require('webpack')
|
2021-09-01 13:18:02 +00:00
|
|
|
const { ESBuildMinifyPlugin } = require('esbuild-loader')
|
2021-08-06 12:50:36 +00:00
|
|
|
|
|
|
|
module.exports = (env) => {
|
|
|
|
let environment = 'development'
|
2021-08-11 07:56:20 +00:00
|
|
|
if (env.ENV) {
|
2021-08-06 12:50:36 +00:00
|
|
|
environment = env.ENV
|
|
|
|
}
|
|
|
|
|
|
|
|
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'],
|
2021-08-11 07:56:20 +00:00
|
|
|
fallback: {
|
2021-08-06 12:50:36 +00:00
|
|
|
"buffer": require.resolve("buffer/"),
|
|
|
|
"crypto": require.resolve("crypto-browserify"),
|
2021-08-12 14:37:21 +00:00
|
|
|
"stream": require.resolve("stream-browserify"),
|
|
|
|
"assert": require.resolve("assert")
|
2021-08-06 12:50:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-08-11 07:56:20 +00:00
|
|
|
test: /\.tsx?$/,
|
2021-09-01 13:18:02 +00:00
|
|
|
loader: 'esbuild-loader',
|
2021-08-11 07:56:20 +00:00
|
|
|
exclude: /node_modules/,
|
2021-09-01 13:18:02 +00:00
|
|
|
options: {
|
|
|
|
loader: 'tsx',
|
|
|
|
target: 'es2018',
|
|
|
|
},
|
2021-08-06 12:50:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'source-map-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf|ico)$/,
|
|
|
|
use: ['file-loader'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-09-01 13:18:02 +00:00
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new ESBuildMinifyPlugin({
|
|
|
|
target: 'es2018',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2021-08-06 12:50:36 +00:00
|
|
|
plugins: [
|
|
|
|
new ForkTsCheckerWebpackPlugin(),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'src/index.html',
|
|
|
|
}),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.ENV': JSON.stringify(environment),
|
|
|
|
}),
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser.js',
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
2021-08-11 07:56:20 +00:00
|
|
|
}),
|
2021-08-06 12:50:36 +00:00
|
|
|
],
|
|
|
|
devServer: {
|
|
|
|
historyApiFallback: true,
|
|
|
|
host: '0.0.0.0',
|
|
|
|
stats: 'errors-only',
|
|
|
|
overlay: true,
|
|
|
|
hot: true,
|
|
|
|
},
|
|
|
|
stats: 'minimal'
|
|
|
|
}
|
|
|
|
}
|