This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
webpack.config.js
74 lines (71 loc) · 1.77 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
69
70
71
72
73
74
const path = require('path')
const webpack = require('webpack')
const fs = require('fs')
const _ = require('lodash')
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
const pageDir = path.join(__dirname, 'src', 'views', 'pages')
const pageEntries = fs
.readdirSync(pageDir)
.filter((name) => name.endsWith('Page.tsx') || name.endsWith('Page'))
.map((name) => {
if (name.endsWith('.tsx')) {
return { name: path.basename(name, 'Page.tsx'), path: path.join(pageDir, name) }
} else {
return {
name: path.basename(name, 'Page'),
path: path.join(
pageDir,
name,
_.startCase(path.basename(name, 'Page')).replace(/ /g, '') + '.tsx'
),
}
}
})
.reduce(
(entries, { name, path }) => ({
...entries,
[name]: {
import: path,
dependOn: 'shared',
},
}),
{}
)
module.exports = {
mode:
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging'
? 'production'
: 'development',
entry: {
...pageEntries,
shared: ['react', 'react-dom', 'moment', 'moment-timezone'],
},
target: 'web',
resolve: {
extensions: ['.ts', '.tsx', '.js'],
plugins: [new TsconfigPathsPlugin()],
fallback: { path: require.resolve('path-browserify') },
},
plugins: [
new webpack.DefinePlugin({
'process.env.npm_package_version': JSON.stringify(process.env.npm_package_version),
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'esbuild-loader',
exclude: '/node_modules/',
options: {
loader: 'tsx',
target: 'es2015',
},
},
],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'src', 'public', 'js'),
},
}