-
Notifications
You must be signed in to change notification settings - Fork 55
/
vue.config.js
126 lines (114 loc) · 3.19 KB
/
vue.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
const webpack = require("webpack");
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
require("events").EventEmitter.defaultMaxListeners = 50;
const packageVersion = `v${envvar("npm_package_version", "0.0.0", true)}`;
let commitHash;
try {
commitHash = process.env.TRUNCATED_GITHUB_SHA ||
require("child_process")
.execSync("git rev-parse --short HEAD")
.toString()
.trim() || "unknown";
} catch (e) {
commitHash = "unknown";
}
function envvar(name, fallback, skipStringify = false) {
let content = process.env[name];
if (content) content = content.trim();
if (skipStringify) return content || fallback;
return JSON.stringify(content || fallback) || '"null"';
}
const noscriptImage = JSON.stringify(
`https://probe.penguin-stats.io/?v=${packageVersion}&p=web&l=1`
);
const templateRoot = path.resolve(
__dirname,
`./src/templates/${envvar("PENGUIN_PLATFORM", "web", true)}`
);
const templateFile = path.resolve(templateRoot, "./index.html");
// 📝📑🛒📋📃
console.log(`
🐧 Current build configured as:
- 📱 Platform (from env:'PENGUIN_PLATFORM'): ${envvar(
"PENGUIN_PLATFORM",
"web",
true
)}
- 📊 Build Hash (from env:'TRUNCATED_GITHUB_SHA' || cmd:'git rev-parse --short HEAD'): ${commitHash}
- 📋 Build Version (from env:'npm_package_version'): ${packageVersion}
- 📋 Template Root: ${templateRoot}
- 📃 Using Template File: ${templateFile}
@ 🛒 Probe
- 📑 <noscript> fallback GET endpoint: ${noscriptImage}
> 📝 Initiating vue-cli-service...`);
module.exports = {
pluginOptions: {
i18n: {
locale: "zh",
fallbackLocale: "en",
localeDir: "locales",
enableInSFC: true,
},
},
// productionSourceMap: false,
devServer: {
proxy: {
"/PenguinStats": {
target: "https://penguin-stats.io/",
// target: "http://localhost:9010/",
// target: "http://10.0.0.164:9010/",
},
},
},
// integrity: false,
runtimeCompiler: true,
transpileDependencies: ["vuetify", "fuse.js", "semver", "protobufjs"],
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
GIT_COMMIT: JSON.stringify(commitHash),
PENGUIN_PLATFORM: envvar("PENGUIN_PLATFORM", "unspecified"),
PENGUIN_BUILDFROM: envvar("PENGUIN_BUILDFROM", null),
PENGUIN_PROBE_NOSCRIPT: noscriptImage,
NPM_PACKAGE_VERSION: JSON.stringify(packageVersion), // stringify
}),
new CopyPlugin({
patterns: [
{
from: templateRoot,
noErrorOnMissing: true,
globOptions: {
ignore: ["**/index.html"],
},
},
],
}),
],
module: {
rules: [
{
test: /\.ya?ml$/,
use: "js-yaml-loader",
},
{
test: /\.md$/,
use: "raw-loader",
},
],
},
},
chainWebpack(config) {
config.plugin("html").tap((args) => {
args[0].template = templateFile;
args[0].minify = {
...args[0].minify,
minifyCSS: true,
minifyJS: true,
}
return args;
});
// we dont need prefetch plugin
config.plugins.delete("prefetch");
},
};