-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
68 lines (64 loc) · 2.46 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = (env, argv) => {
// Determine if we're in development mode
const isDevelopment = argv.mode === 'development';
// Check for Cloudflare Pages environment
const isCloudflarePages = process.env.CF_PAGES === '1';
const isProductionBranch = isCloudflarePages && (process.env.CF_PAGES_BRANCH === 'release');
const isPreviewBranch = isCloudflarePages && (process.env.CF_PAGES_BRANCH === 'main');
const apiUrl = isDevelopment ? '"http://localhost:8787"' : '"https://probi-oh-api.gdare1.workers.dev"';
// Set LOG based on our conditions
const shouldLog = isDevelopment || (isPreviewBranch);
return {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.[contenthash].js',
clean: true,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.aliases.json" })]
},
devtool: isDevelopment || isPreviewBranch ? 'eval-source-map' : false,
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
favicon: "./public/favicon.ico"
}),
new webpack.DefinePlugin({
'process.env.LOG': shouldLog,
'process.env.DEVELOPMENT': isDevelopment,
'process.env.PREVIEW': isPreviewBranch,
'process.env.PRODUCTION': isProductionBranch,
'process.env.API_URL': apiUrl,
}),
],
devServer: {
static: path.join(__dirname, 'dist'),
compress: true,
port: 4000,
},
};
};