This repository was archived by the owner on Jan 30, 2023. It is now read-only.
generated from Beelink/boilerplate-vue
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue.config.js
131 lines (126 loc) · 4.73 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
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-var-requires */
const webpack = require("webpack");
const MomentLocalesPlugin = require("moment-locales-webpack-plugin"); // for moment tree shaking locales
const PreloadWebpackPlugin = require("@vue/preload-webpack-plugin");
module.exports = {
pwa: {
name: "NeuTodo",
themeColor: "#121212",
msTileColor: "#121212",
appleMobileWebAppStatusBarStyle: "black-translucent",
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",
},
},
publicPath: process.env.NODE_ENV === "github" ? "/neu-todo/" : "/",
outputDir: process.env.NODE_ENV === "github" ? "docs" : "dist",
runtimeCompiler: true,
productionSourceMap: process.env.NODE_ENV !== "production",
crossorigin: "use-credentials",
lintOnSave: true,
configureWebpack: (config) => {
if (process.env.NODE_ENV === "development") {
config.devtool = "source-map";
} else if (process.env.NODE_ENV === "test") {
config.devtool = "cheap-module-eval-source-map";
}
},
chainWebpack: (config) => {
// for moment tree shaking locales
config.resolve.alias.set("moment", "moment/moment.js");
// these settings apply to production or development, but will break mocha tests in the test NODE_ENV
if (
process.env.NODE_ENV === "production" ||
process.env.NODE_ENV === "development"
) {
// By default vue-cli sets rel=prefetch on chunks-vendor.js and app.js in the index.html that gets generated in index.html.
// This setting removes vue-cli's this default so we can use more chunks and let them be loaded dynamically.
config.plugins.delete("prefetch");
config.plugin("prefetch").use(PreloadWebpackPlugin, [
{
rel: "prefetch",
include: "asyncChunks",
// do not prefetch async routes
fileBlacklist: [/myasyncRoute(.)+?\.js$/, /\.map$/],
},
{
rel: "preload",
include: "initial",
fileWhitelist: [/(^@vue)(.*)(\.js$)/, /(^vue)(.*)(\.js$)/],
// do not preload map files or hot update files
fileBlacklist: [/\.map$/, /hot-update\.js$/],
},
]);
// override vue's default chunks because their chunking is too big.
config.optimization.delete("splitChunks");
config.optimization.set("splitChunks", {
cacheGroups: {
// Vue modules
vue: {
test: /[\\/]node_modules[\\/](@vue.*|vue.*)[\\/]/,
name: "vue",
enforce: true,
priority: 20,
chunks: "initial",
},
// all other modules modules
vendors: {
name: "chunk-vendors",
test(module, chunks) {
// `module.resource` contains the absolute path of the file on disk.
// Note the usage of `path.sep` instead of / or \, for cross-platform compatibility.
const path = require("path");
return (
module.resource &&
!module.resource.includes(
`${path.sep}node_modules${path.sep}@vue`
) &&
!module.resource.includes(
`${path.sep}node_modules${path.sep}vue`
) &&
!module.resource.includes(`${path.sep}src${path.sep}`)
);
},
maxSize: 500000,
priority: 10,
enforce: true,
chunks: "all", // doesn't get created without 'all' here
},
// default common chunk settings from Vue
common: {
name: "chunk-common",
minChunks: 2,
priority: 5,
chunks: "initial",
reuseExistingChunk: true,
},
},
});
// Webpack includes a small piece of runtime code that gets inserted into the last chunk created. This could cause our vendor
// chunk to change unnecessarily. So the next line causes this runtime to be put in a separate file.
config.optimization.set("runtimeChunk", true);
}
if (process.env.NODE_ENV === "production") {
// for moment tree shaking locales
// Include only 'en-us' (which is always included) and 'es-us' locales
config
.plugin("moment")
.use(MomentLocalesPlugin, [
{
localesToKeep: ["es-us"],
},
])
.use(
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
})
);
}
},
};