This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
75 lines (67 loc) · 2.04 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
/* eslint-env node */
import * as path from 'path'
import { Configuration } from 'webpack'
import { UserscriptPlugin } from 'webpack-userscript'
import { homepage } from './package.json'
import { currentTag, UserScripts } from './utils'
const HERE = path.resolve(__dirname)
const OUTPUT = path.resolve(HERE, 'dist')
const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT ?? '8842')
const VERSION = process.env.VERSION ?? currentTag().replace(/^v/, '')
const config: (
env: Record<string, unknown>,
args: Record<string, unknown>
) => Configuration = (_, argv) => {
const isDevMode = argv.mode === 'development'
/* istanbul ignore next */
const downloadUrl = isDevMode
? `http://localhost:${DEV_SERVER_PORT}`
: `${homepage}/releases/latest/download/`
/* istanbul ignore next */
const proxyScript = isDevMode
? {
baseURL: `http://localhost:${DEV_SERVER_PORT}/`,
filename: '[basename].proxy.user.js',
}
: undefined
const scripts = new UserScripts()
const plugin = new UserscriptPlugin({
metajs: true,
pretty: true,
downloadBaseURL: downloadUrl,
strict: !isDevMode,
proxyScript,
headers: (original, ctx) => {
const name = ctx.fileInfo.basename
const { homepage, supportURL } = original
return {
...original,
name,
namespace: homepage,
homepage: `${homepage}/tree/main/scripts/${name}`,
supportURL: `${supportURL}?q=is:issue+is%3Aopen+label:${name}`,
version: isDevMode ? `${VERSION}-build.[buildNo]` : VERSION,
...scripts.headers[name],
}
},
})
return {
entry: scripts.entries,
module: { rules: [{ test: /\.ts$/, loader: 'swc-loader' }] },
resolve: { extensions: ['.js', '.ts'] },
output: {
clean: true,
path: OUTPUT,
filename: '[name].user.js',
},
plugins: [plugin],
devtool: false,
devServer: {
static: { directory: OUTPUT, serveIndex: true },
port: DEV_SERVER_PORT,
hot: false,
liveReload: false,
},
}
}
export default config