-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
webpack.config.userscript.js
128 lines (109 loc) · 3.04 KB
/
webpack.config.userscript.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
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
let git = {};
{
let gitPlugin = new GitRevisionPlugin({
branch: true,
lightweightTags: true
});
git.version = gitPlugin.version();
git.commit = gitPlugin.commithash();
git.branch = gitPlugin.branch();
}
let changelog = '';
{
const changelogFile = "changelog.json";
if(!fs.existsSync(changelogFile)) {
console.log(`couldn't find ${changelogFile}`);
process.exit(1);
}
changelog = fs.readFileSync(changelogFile, "utf8");
}
const logo_data_b64 = "data:image/svg+xml;base64," + btoa(fs.readFileSync("./assets/logo/logo.svg", "utf8"));
module.exports = (_env, argv) => {
const is_prod = argv.mode === "production";
const source_output_path = path.join(
path.resolve(__dirname), "builds", "userscript", is_prod ? "prod" : "dev"
);
let config = {
performance: {
hints: false
},
context: __dirname,
node: { __filename: true, __dirname: true },
target: "web",
mode: is_prod ? "production" : "development",
entry: {
["vttes.user.js"]: "./src/entrypoints/userscript.ts",
},
output: {
path: source_output_path,
filename: '[name]',
},
module: {
rules: [
{
test: /(\.js|\.jsx)$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
plugins: [
[
'transform-define',
{
'process.env.BUILD_TARGET': "chrome",
'process.env.NODE_ENV': is_prod ? "production" : "development",
}
],
]
}
}],
},
{
test: /(\.ts|\.tsx)$/,
loaders: ['awesome-typescript-loader']
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
modules: [
'src',
'node_modules',
],
},
plugins: [
new webpack.DefinePlugin({
"BUILD_CONSTANT_VERSION": JSON.stringify(git.version),
"BUILD_CONSTANT_COMMIT": JSON.stringify(git.commit),
"BUILD_CONSTANT_BRANCH": JSON.stringify(git.branch),
"BUILD_CONSTANT_TARGET_PLATFORM": JSON.stringify("userscript"),
"BUILD_CONSTANT_CHANGELOG": JSON.stringify(changelog),
'BUILD_CONSTANT_VTTES_IS_DEV': JSON.stringify(is_prod === false),
'BUILD_CONSTANT_LOGO_B64': `"${logo_data_b64}"`,
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
};
if(is_prod) {
config.optimization = {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false,
},
},
test: /\.js$|\.jsx$|\.ts$|\.tsx$/i,
parallel: true,
})
]
};
}
return config;
};