forked from raiden-network/light-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vue.config.js
141 lines (124 loc) · 4.3 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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const VersionFile = require('webpack-version-file-plugin');
const { DefinePlugin } = require('webpack');
const { InjectManifest } = require('workbox-webpack-plugin');
const sourceDirectoryPath = path.resolve(__dirname, 'src');
const distributionDirectoryPath = path.resolve(__dirname, 'dist');
function getPackageVersion() {
const packageInfo = require('./package.json');
return packageInfo.version ?? '0.0.0';
}
/*
* Note that it is not necessary to exclude the version file from the to
* cache assets. The version file gets generated during the build and is
* thereby not included in the pre-cache manifest. The same goes for the
* worker script itself.
*/
function setupServiceWorkerRelatedPlugins(config) {
if (process.env.NODE_ENV !== 'production') return;
const versionFilePlugin = new VersionFile({
packageFile: path.join(__dirname, 'package.json'),
template: path.join(__dirname, 'version.ejs'),
outputFile: path.join(distributionDirectoryPath, 'version.json'),
});
const versionEnvironmentVariablePlugin = new DefinePlugin({
'process.env': {
PACKAGE_VERSION: "'" + getPackageVersion() + "'",
},
});
const injectServiceWorkerPlugin = new InjectManifest({
swSrc: path.join(sourceDirectoryPath, 'service-worker', 'worker'),
swDest: 'service-worker.js',
maximumFileSizeToCacheInBytes: 20e6,
});
config.plugins.push(
versionFilePlugin,
versionEnvironmentVariablePlugin,
injectServiceWorkerPlugin,
);
}
module.exports = {
productionSourceMap: false,
// https://forum.vuejs.org/t/solution-to-building-error-in-circleci-or-any-other-machine-with-cpu-limitations/40862
parallel: !process.env.CIRCLECI,
publicPath: process.env.VUE_APP_PUBLIC_PATH ? process.env.VUE_APP_PUBLIC_PATH : '/',
chainWebpack: (config) => {
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
config.module
.rule('raiden-source-maps')
.test(/\.js$/)
.pre()
.use('source-map-loader')
.loader('source-map-loader');
}
config.module
.rule('i18n')
.resourceQuery(/blockType=i18n/)
.type('javascript/auto')
.use('i18n')
.loader('@kazupon/vue-i18n-loader')
.end();
},
pluginOptions: {
i18n: {
locale: 'en',
fallbackLocale: 'en',
localeDir: 'locales',
enableInSFC: true,
},
},
css: {
extract: {
ignoreOrder: true,
},
},
// check -> https://github.com/vuejs/vue-cli/issues/2978
configureWebpack: (config) => {
if (process.env.NODE_ENV === 'development') {
config.devtool = 'eval-source-map';
config.output.devtoolFallbackModuleFilenameTemplate = 'webpack:///[resource-path]?[hash]';
config.output.devtoolModuleFilenameTemplate = (info) => {
const isVue = info.resourcePath.match(/\.vue$/);
const isScript = info.query.match(/type=script/);
const hasModuleId = info.moduleId !== '';
// Detect generated files, filter as webpack-generated
if (
// Must result from vue-loader
isVue &&
// Must not be 'script' files (enough for chrome), or must have moduleId (firefox)
(!isScript || hasModuleId)
) {
let pathParts = info.resourcePath.split('/');
const baseName = pathParts[pathParts.length - 1];
// prepend 'generated-' to filename as well, so it's easier to find desired files via Ctrl+P
pathParts.splice(-1, 1, `generated-${baseName}`);
return `webpack-generated:///${pathParts.join('/')}?${info.hash}`;
}
// If not generated, filter as webpack-vue
return `webpack-vue:///${info.resourcePath}`;
};
}
const patterns = [];
if (process.env.DEPLOYMENT_INFO && process.env.DEPLOYMENT_SERVICES_INFO) {
patterns.push(
{
from: path.resolve(process.env.DEPLOYMENT_INFO),
to: distributionDirectoryPath,
},
{
from: path.resolve(process.env.DEPLOYMENT_SERVICES_INFO),
to: distributionDirectoryPath,
},
);
}
if (patterns.length > 0) {
config.plugins.push(
new CopyWebpackPlugin({
patterns: patterns,
}),
);
}
setupServiceWorkerRelatedPlugins(config);
},
};