forked from kitsuned/AltHome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
165 lines (160 loc) · 3.1 KB
/
webpack.config.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { BannerPlugin, ProvidePlugin, DefinePlugin } from 'webpack';
import CopyPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import TSConfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import {
JsonTransformer,
AresPackagerPlugin,
PermissionPlugin,
WebOSBrewManifestPlugin,
WebpackMultipleConfigurations,
} from 'chore/webpack-utils';
import { name, version, description } from './package.json';
const transformer = new JsonTransformer({
APP_ID: name,
APP_VERSION: version,
});
export default <WebpackMultipleConfigurations<{ WEBPACK_SERVE?: boolean; }>>[
{
name: 'installer',
target: 'node8',
mode: 'production',
entry: './src/installer/index.ts',
output: {
filename: 'install',
clean: true,
},
resolve: {
extensions: [
'.ts',
'.js',
],
},
module: {
rules: [
{
test: /.ts$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'node8',
},
},
],
},
plugins: [
new DefinePlugin({
'process.env.APP_ID': JSON.stringify(name),
}),
new BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true,
}),
new PermissionPlugin(),
],
},
(_, argv) => ({
name: 'app',
target: 'web',
mode: argv.mode ?? 'development',
entry: './src/index.tsx',
devtool: argv.mode === 'production' ? 'source-map' : 'eval',
devServer: {
hot: true,
},
output: {
filename: 'app.js',
},
resolve: {
extensions: [
...argv.mode !== 'development' ? [] : ['.dev.ts'],
'.js',
'.ts',
'.tsx',
],
plugins: [
new TSConfigPathsPlugin(),
],
},
module: {
rules: [
{
test: /.tsx?$/,
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'chrome79',
},
},
{
test: /.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
'autoprefixer',
'postcss-preset-env',
],
},
},
},
],
},
],
},
performance: {
hints: false,
},
plugins: [
new ProvidePlugin({
React: 'react',
}),
new DefinePlugin({
__DEV__: JSON.stringify(!process.env.PRODUCTION),
'process.env.APP_ID': JSON.stringify(name),
}),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: './src/app/index.html',
}),
new CopyPlugin({
patterns: [
{
from: '**/*',
context: 'manifests',
priority: 10,
},
{
from: '**/*.json',
context: 'manifests',
transform: transformer.transform,
priority: 0,
},
],
}),
],
}),
env => ({
name: 'ares',
entry: {},
dependencies: [
'app',
'installer',
],
plugins: !env?.WEBPACK_SERVE ? [
new AresPackagerPlugin(),
new WebOSBrewManifestPlugin({
appDescription: description,
sourceUrl: 'https://github.com/kitsuned/AltHome',
iconUri: './manifests/icon320.png',
rootRequired: true,
}),
] : [],
}),
];