-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.service.ts
99 lines (92 loc) · 1.96 KB
/
webpack.service.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
import { DefinePlugin } from 'webpack';
import CopyPlugin from 'copy-webpack-plugin';
import { JsonTransformer } from 'webpack-utils';
import type { WebpackConfigFunction } from 'webpack-utils';
import { id, version } from './package.json';
const SERVICE_ID = `${id}.service`;
const transformer = new JsonTransformer({
APP_ID: id,
APP_VERSION: version,
SERVICE_ID,
});
const config: WebpackConfigFunction<{ WEBPACK_SERVE?: boolean }> = (_, argv) => ({
id: SERVICE_ID,
name: 'service',
mode: argv.mode ?? 'development',
target: 'node8.12',
entry: './service/index.ts',
output: {
filename: 'service.js',
},
externals: {
palmbus: 'commonjs palmbus',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
// TODO: move to Babel
{
test: /.[jt]sx?$/,
loader: 'babel-loader',
options: {
presets: [
['@babel/env', { targets: { node: 12 } }],
['@babel/typescript', { onlyRemoveTypeImports: true }],
],
},
},
{
test: /.source.\w+$/,
type: 'asset/source',
loader: 'babel-loader',
options: {
presets: [
[
'@babel/env',
{
// surface manager uses a custom JS engine: QT V4
// let's set target to something ancient just to cover ES3
targets: { chrome: 4 },
},
],
],
plugins: [
[
'minify-replace',
{
replacements: [
{
identifierName: '__APP_ID__',
replacement: {
type: 'stringLiteral',
value: id,
},
},
],
},
],
],
},
},
],
},
plugins: [
new DefinePlugin({
__DEV__: JSON.stringify(argv.mode === 'development'),
'process.env.APP_ID': JSON.stringify(id),
'process.env.SERVICE_ID': JSON.stringify(SERVICE_ID),
}),
new CopyPlugin({
patterns: [
{
from: '*.json',
context: 'manifests/service',
transform: transformer.transform,
},
],
}),
],
});
export default config;