-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
227 lines (213 loc) · 9.05 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Read version from package.json
const fs = require('fs')
const packageJson = fs.readFileSync('./package.json')
const version = JSON.parse(packageJson).version || 0
const webpack = require('webpack');
const WebpackBeforeBuildPlugin = require('before-build-webpack');
const config = require('./src/config');
// Stamp service worker with current version string!
const fileNameIn = "service-worker-source.js";
const fileNameOut = "service-worker-versioned.js";
fs.readFile(fileNameIn, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/APP_VERSION_PLACEHOLDER/g, "'" + version + "'");
fs.writeFile(fileNameOut, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
module.exports = {
devServer: {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
},
proxy: {
"^/localproxy": {
changeOrigin: true,
//followRedirects: true,
target: "localhost",
router: function (req) {
// Remove "/localproxy"
var path = req.originalUrl.substring(12);
// Host is the first segment
path = path.substring(0, path.indexOf("/"));
var host = path;
return {
protocol: 'https:',
host: host,
}
},
pathRewrite: function (path, req) {
// Remove the first segment, that is the host
var p = path.substring(12);
p = p.substring(p.indexOf("/"));
return p;
},
logLevel: 'debug',
secure: false
},
}
},
publicPath: process.env.NODE_ENV === 'production'
? './'
: './',
chainWebpack: config => {
config.plugin('html').tap(args => {
// Stamp the title into the HTML page
const config = require('./src/config');
args[0].title = config.appName;
return args;
})
},
pwa: {
name: config.appName,
themeColor: "#0E813D",
appleMobileWebAppCapable: 'yes',
appleMobileWebAppStatusBarStyle: 'black',
manifestOptions: {
start_url: "./index.html",
background_color: "#FFFFFF",
display: "standalone",
iconPaths: {
favicon32: 'img/icons/favicon-32x32.png',
favicon16: 'img/icons/favicon-16x16.png',
appleTouchIcon: 'img/icons/apple-touch-icon-152x152.png',
maskIcon: 'img/icons/safari-pinned-tab.svg',
msTileImage: 'img/icons/msapplication-icon-144x144.png'
},
"icons": [
{
"src": "./img/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "./img/icons/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "./img/icons/apple-touch-icon-60x60.png",
"sizes": "60x60",
"type": "image/png"
},
{
"src": "./img/icons/apple-touch-icon-76x76.png",
"sizes": "76x76",
"type": "image/png"
},
{
"src": "./img/icons/apple-touch-icon-120x120.png",
"sizes": "120x120",
"type": "image/png"
},
{
"src": "./img/icons/apple-touch-icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "./img/icons/apple-touch-icon-180x180.png",
"sizes": "180x180",
"type": "image/png"
},
{
"src": "./img/icons/apple-touch-icon.png",
"sizes": "180x180",
"type": "image/png"
},
{
"src": "./img/icons/favicon-16x16.png",
"sizes": "16x16",
"type": "image/png"
},
{
"src": "./img/icons/favicon-32x32.png",
"sizes": "32x32",
"type": "image/png"
},
{
"src": "./img/icons/msapplication-icon-144x144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "./img/icons/mstile-150x150.png",
"sizes": "150x150",
"type": "image/png"
}
],
},
workboxPluginMode: 'InjectManifest',
workboxOptions: {
swSrc: 'service-worker-versioned.js',
swDest: 'service-worker.js',
exclude: [
'assets/fonts/', /\.map$/
]
}
},
configureWebpack: {
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env': {
PACKAGE_VERSION: '"' + version + '"'
},
}),
new WebpackBeforeBuildPlugin(function (stats, callback) {
// Do whatever you want...
console.log("********* Processing icons **************");
const iconTemplate = "<template>SVGDATA</template>\n<script>\nexport default { name: 'ICONNAME'};\n</script>\n<style scoped>\npath {fill: currentColor !important;}\n</style>\n";
const iconTemplateImg = "<template><img src='IMAGEPATH'/></template>\n<script>\nexport default { name: 'ICONNAME'};\n</script>\n<style scoped>\npath {fill: currentColor !important;}\n</style>\n";
fs.readdirSync('./src/assets/icons').forEach(file => {
if (file.endsWith(".svg")) {
fs.readFile('./src/assets/icons/' + file, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var iconName = file.split('.')[0];
var result = iconTemplate.replace(/SVGDATA/g, data);
result = result.replace(/ICONNAME/g, iconName);
// Remove possible <?xml tag
result = result.replace(/<\?xml[^\?]*\?>/g, "");
// Add icon specific class name
result = result.replace(/<svg/g, "<svg class=\"icon-" + iconName + "\"");
const outFileName = "Icon" + iconName.substring(0, 1).toUpperCase() + iconName.substring(1) + ".vue";
fs.readFile('./src/icons/' + outFileName, 'utf8', function (err, oldData) {
if (!err && oldData == result) {
// No change
return;
}
fs.writeFile('./src/icons/' + outFileName, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
});
} else if (file.endsWith(".jpg") || file.endsWith(".png")) {
var iconName = file.split('.')[0];
var result = iconTemplateImg.replace(/IMAGEPATH/g, "../assets/icons/" + file);
result = result.replace(/ICONNAME/g, iconName);
// Add icon specific class name
result = result.replace(/<img/g, "<img class=\"icon-" + iconName + "\"");
const outFileName = "Icon" + iconName.substring(0, 1).toUpperCase() + iconName.substring(1) + ".vue";
fs.readFile('./src/icons/' + outFileName, 'utf8', function (err, oldData) {
if (!err && oldData == result) {
// No change
return;
}
fs.writeFile('./src/icons/' + outFileName, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
}
});
callback(); // don't call it if you do want to stop compilation
}, ['beforeCompile']),
]
},
lintOnSave: 'warning',
}