-
Notifications
You must be signed in to change notification settings - Fork 4
/
vue.config.js
174 lines (158 loc) · 4.79 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const path = require("path");
const webpack = require("webpack");
const CopyPlugin = require("copy-webpack-plugin");
const globals = require("./shared/smartcharge-globals.json");
let commitHash =
process.env.SOURCE_VERSION ||
require("child_process")
.execSync("git rev-parse --short HEAD")
.toString()
.trim();
module.exports = {
outputDir: path.resolve(__dirname, "./dist/app"),
pages: {
index: {
entry: "app/src/main.ts",
template: "app/public/index.html",
filename: "index.html",
},
},
devServer: {
proxy: {
[globals.API_PATH]: {
//"https://smartcharge-dev.herokuapp.com",
target: `http://localhost:${
process.env.SERVER_PORT || globals.DEFAULT_PORT
}`,
ws: true,
},
},
contentBase: [
path.resolve(__dirname, "app/public"),
path.resolve(__dirname, "public"),
],
},
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
COMMIT_HASH: JSON.stringify(commitHash),
}),
new CopyPlugin([
{
from: path.resolve(__dirname, "./app/public/"),
to: ".",
ignore: ["index.html", ".DS_Store"],
},
]),
],
},
chainWebpack: (config) => {
config.entry("app").clear().add("./app/src/main.ts").end();
// Not needed anymore?
//config.resolve.alias.delete("@");
//config.resolve.alias.set("@app", path.resolve("./app/src"));
//config.resolve.alias.set("@shared", path.resolve("./shared"));
//config.resolve.alias.set("@providers", path.resolve("./providers"));
//config.resolve.alias.set("@server", path.resolve("./server"));
// Remove warnings regaring files that are omitted by TS because they only contain interfaces
config
.plugin("IgnoreNotFoundExportPlugin")
.before("friendly-errors")
.use(IgnoreNotFoundExportPlugin, [
{
sourceFiles: [/\/shared\/sc-schema$/],
},
]);
config.plugin("type-graphql").use(webpack.NormalModuleReplacementPlugin, [
/type-graphql$/,
(resource) => {
resource.request = resource.request.replace(
/type-graphql/,
"type-graphql/dist/browser-shim"
);
},
]);
},
pwa: {
workboxOptions: {
skipWaiting: true,
},
},
};
/***
*
* INLINE IgnoreNotFoundExportPlugin from https://github.com/TypeStrong/ts-loader/issues/653#issuecomment-467403243
* Thanks to https://github.com/iyinchao
*
* ***/
const ModuleDependencyWarning = require("webpack/lib/ModuleDependencyWarning");
class IgnoreNotFoundExportPlugin {
constructor(option) {
const op = {
sourceFiles: [],
exportNames: [],
...option,
};
this.ignoredSourceFiles = op.sourceFiles;
this.ignoredExportNames = op.exportNames;
}
apply(compiler) {
const reg = /export '(.*)'.* was not found in '(.*)'/;
const doneHook = (stats) => {
stats.compilation.warnings = stats.compilation.warnings.filter((warn) => {
if (!(warn instanceof ModuleDependencyWarning) || !warn.message) {
return true;
}
const matchedResult = warn.message.match(reg);
if (!matchedResult) {
return true;
}
const [, exportName, sourceFile] = matchedResult;
const customRulesIgnore = {
exportNames: false,
sourceFiles: false,
};
if (this.ignoredExportNames.length) {
for (let i = 0; i < this.ignoredExportNames.length; i++) {
const rule = this.ignoredExportNames[i];
if (typeof rule === "string" && rule === exportName) {
customRulesIgnore.exportNames = true;
break;
} else if (rule instanceof RegExp && rule.test(exportName)) {
customRulesIgnore.exportNames = true;
break;
}
}
} else {
customRulesIgnore.exportNames = true;
}
if (this.ignoredSourceFiles.length) {
for (let i = 0; i < this.ignoredSourceFiles.length; i++) {
const rule = this.ignoredSourceFiles[i];
if (typeof rule === "string" && rule === sourceFile) {
customRulesIgnore.sourceFiles = true;
break;
} else if (rule instanceof RegExp && rule.test(sourceFile)) {
customRulesIgnore.sourceFiles = true;
break;
}
}
} else {
customRulesIgnore.sourceFiles = true;
}
let ret = false;
Object.keys(customRulesIgnore).forEach((key) => {
if (!customRulesIgnore[key]) {
ret = true;
}
});
return ret;
});
};
if (compiler.hooks) {
compiler.hooks.done.tap("IgnoreNotFoundExportPlugin", doneHook);
} else {
compiler.plugin("done", doneHook);
}
}
}