-
Notifications
You must be signed in to change notification settings - Fork 40
/
webpack.config.js
147 lines (143 loc) · 3.33 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
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
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
//const { transform } = require('ts-transform-react-jsx-source') // outdated, not compatible with Typescript 5.0+
module.exports = (env, argv) => {
var commonConfig = {
plugins: [
new ForkTsCheckerWebpackPlugin(),
]
};
var extensionConfig = {
...commonConfig,
target: 'node',
entry: {
extension: './src/extension.ts',
debugAdapter: { import: './src/debugAdapter.ts', dependOn: 'extension' }
},
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]'
},
devtool: (argv.mode === 'development') ? 'inline-source-map' : undefined,
externals: {
vscode: 'commonjs vscode'
},
resolve: {
mainFields: ['browser', 'module', 'main'],
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: argv.mode === 'production',
}
}
]
},
{
test: /\.md$/,
loader: 'raw-loader',
},
]
},
optimization: {
minimize: argv.mode !== 'development',
minimizer: [new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
})]
}
};
var clientConfig = {
...commonConfig,
entry: "./src/client/client.tsx",
output: {
filename: "client.js",
},
devtool: (argv.mode === 'development') ? 'inline-source-map' : undefined,
resolve: {
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"],
alias: {
"react": "preact/compat",
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat", // Must be below test-utils
"react/jsx-runtime": "preact/jsx-runtime"
}
},
performance: {
maxAssetSize: 1000000,
maxEntrypointSize: 1000000
},
module: {
rules: [
{ // get source maps from node_modules
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"],
},
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {
configFile: 'tsconfig.client.json',
transpileOnly: argv.mode === 'production',
//getCustomTransformers() { return argv.mode === 'development' ? { before: [transform()], } : {}; }, // get preact component stack (doesn't print it anywhere, so disabled for now)
},
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
auto: /\.module\.css$/i,
localIdentName: (argv.mode === 'development') ? '[folder][name]__[local]' : '[hash:base64]',
},
sourceMap: argv.mode === 'development',
},
}
],
},
{
test: /\.svg$/,
loader: 'svg-inline-loader',
},
{
test: /\.(vert|frag|md)$/,
loader: 'raw-loader',
},
],
},
optimization: {
minimize: argv.mode !== 'development',
minimizer: [new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
})]
},
plugins: [
//new webpack.debug.ProfilingPlugin()
]
};
return [extensionConfig, clientConfig];
};