-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
61 lines (57 loc) · 1.36 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
const glob = require('glob')
const path = require('node:path')
const fs = require('node:fs')
const webpack = require('webpack')
const pageEntries = glob
.sync('./src/**/*Page.tsx')
.filter(fileUsesHydration)
.map((filePath) => {
return { name: path.basename(filePath, '.tsx'), path: filePath }
})
.reduce(
(entries, { name, path }) => ({
...entries,
[name]: {
import: path,
dependOn: 'shared',
},
}),
{}
)
function fileUsesHydration(filePath) {
const fileContents = fs.readFileSync(filePath, 'utf-8')
return fileContents.includes('withBrowserBundle(')
}
module.exports = {
mode: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging' ? 'production' : 'development',
entry: {
...pageEntries,
shared: ['react', 'react-dom'],
},
target: 'web',
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
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, 'dist', 'assets', 'js'),
},
}