forked from matomo-org/matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
134 lines (113 loc) · 4 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
const fs = require('fs');
const path = require('path');
const pluginExternals = getPluginExternals();
function scanPluginExternals() {
const pluginExternals = {};
const pluginsDir = path.join(__dirname, 'plugins');
for (let pluginName of fs.readdirSync(pluginsDir)) {
const vuePackageFolder = path.join(pluginsDir, pluginName, 'vue', 'src');
if (!fs.existsSync(vuePackageFolder)) {
continue;
}
pluginExternals[pluginName] = pluginName;
}
return pluginExternals;
}
function getPluginExternals() {
if (!process.env.MATOMO_ALL_PLUGINS) {
return scanPluginExternals();
}
const allPluginsWithVueFolder = process.env.MATOMO_ALL_PLUGINS.split(',');
return Object.fromEntries(allPluginsWithVueFolder.map((name) => [name, name]));
}
if (!process.env.MATOMO_CURRENT_PLUGIN) {
console.log("The MATOMO_CURRENT_PLUGIN environment variable is not set!");
}
const pluginPath = process.env.MATOMO_CURRENT_PLUGIN || '';
const pluginName = path.basename(pluginPath);
const srcPath = `${pluginPath}/vue/src/`;
const publicPath = `${pluginPath}/vue/dist/`;
// hack to get publicPath working for lib build target (see https://github.com/vuejs/vue-cli/issues/4896#issuecomment-569001811)
function PublicPathWebpackPlugin() {}
PublicPathWebpackPlugin.prototype.apply = function (compiler) {
compiler.hooks.entryOption.tap('PublicPathWebpackPlugin', (context, entry) => {
if (entry['module.common']) {
entry['module.common'] = path.resolve(__dirname, './src/main.js');
}
if (entry['module.umd']) {
entry['module.umd'] = path.resolve(__dirname, './src/main.js');
}
if (entry['module.umd.min']) {
entry['module.umd.min'] = path.resolve(__dirname, './src/main.js');
}
});
compiler.hooks.beforeRun.tap('PublicPathWebpackPlugin', (compiler) => {
compiler.options.output.publicPath = publicPath;
});
};
const detectedDependentPlugins = [];
function OutputDetectedDependentPluginsPlugin() {}
OutputDetectedDependentPluginsPlugin.prototype.apply = function (compiler) {
compiler.hooks.afterCompile.tap('OutputDetectedDependentPluginsPlugin', (context, entry) => {
const metadataPath = path.join(publicPath, 'umd.metadata.json');
const metadata = {
dependsOn: detectedDependentPlugins,
};
if (fs.existsSync(srcPath)) {
fs.mkdirSync(path.dirname(metadataPath), {recursive: true});
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
}
});
};
module.exports = {
publicPath,
chainWebpack: config => {
config.plugin('output-detected-dependent-plugins').use(OutputDetectedDependentPluginsPlugin);
config.plugin('public-path-webpack').use(PublicPathWebpackPlugin);
config.externals(function (context, request, callback) {
if (request === 'tslib') {
callback(null, 'tslib');
return;
}
if (pluginExternals[request]) {
if (detectedDependentPlugins.indexOf(request) === -1
&& request !== pluginName
) {
detectedDependentPlugins.push(request);
}
callback(null, pluginExternals[request]);
return;
}
callback();
});
// disable asset size warnings
config.performance.hints(false);
config.watchOptions({
ignored: /node_modules/,
});
// override config so we can generate type definitions for plugin libraries
// see https://github.com/vuejs/vue-cli/issues/6543
if (process.env.NODE_ENV !== 'development') {
config.module
.rule('ts')
.uses
.delete('thread-loader');
config.module
.rule('ts')
.use('ts-loader')
.tap((options) => {
options.transpileOnly = false;
options.happyPackMode = false;
options.compilerOptions = {
declaration: true,
noEmit: false,
outDir: `${__dirname}/@types/${pluginName}`,
paths: {
'*': [`${__dirname}/@types/*`, `${__dirname}/node_modules/*`, '*']
},
};
return options;
});
}
},
};