-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.app.ts
128 lines (122 loc) · 2.69 KB
/
webpack.app.ts
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { ProvidePlugin, DefinePlugin } from 'webpack';
import CopyPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TSConfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import { JsonTransformer } from 'webpack-utils';
import type { WebpackConfigFunction } from 'webpack-utils';
import { id, version } from './package.json';
const transformer = new JsonTransformer({
APP_ID: id,
APP_VERSION: version,
});
const config: WebpackConfigFunction<{ WEBPACK_SERVE?: boolean }> = (_, argv) => ({
id,
name: 'app',
target: 'web',
mode: argv.mode ?? 'development',
entry: './src/index.tsx',
devtool: 'source-map',
devServer: {
hot: true,
},
output: {
filename: 'app.js',
},
resolve: {
extensions: [...(argv.mode !== 'development' ? [] : ['.dev.ts']), '.js', '.ts', '.tsx'],
plugins: [new TSConfigPathsPlugin()],
},
module: {
rules: [
{
test: /\.[mc]?[jt]sx?$/,
exclude: [/node_modules\/core-js/],
use: {
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
[
'@babel/env',
{
useBuiltIns: 'usage',
corejs: '3.37',
targets: { chrome: 79 }, // corresponds to webOS 6
},
],
['@babel/react'],
['@babel/typescript', { onlyRemoveTypeImports: true }],
],
plugins: [
['transform-typescript-metadata'],
['@babel/plugin-proposal-decorators', { version: 'legacy' }],
['@babel/plugin-transform-class-properties'],
],
},
},
},
{
test: /.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: ['autoprefixer', 'postcss-preset-env'],
},
},
},
],
},
{
test: /.png$/,
type: 'asset/resource',
generator: {
filename: 'assets/[hash][ext]',
},
},
],
},
performance: {
hints: false,
},
plugins: [
new ProvidePlugin({
React: 'react',
}),
new DefinePlugin({
__DEV__: JSON.stringify(argv.mode === 'development'),
'process.env.APP_ID': JSON.stringify(id),
}),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: './src/app/index.html',
}),
new CopyPlugin({
patterns: [
{
from: '**/*',
context: 'manifests/app',
priority: 10,
},
{
from: '**/*.json',
context: 'manifests/app',
transform: transformer.transform,
priority: 0,
},
{
from: 'agentd*',
context: 'agent',
to: 'service',
toType: 'file',
},
],
}),
],
});
export default config;