forked from matomo-org/matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
89 lines (74 loc) · 2.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
const fs = require('fs');
const path = require('path');
const pluginExternals = scanPluginExternals();
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;
}
if (!process.env.MATOMO_CURRENT_PLUGIN) {
console.log("The MATOMO_CURRENT_PLUGIN environment variable is not set!");
}
const publicPath = `plugins/${process.env.MATOMO_CURRENT_PLUGIN}/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(__dirname, publicPath, 'umd.metadata.json');
const metadata = {
dependsOn: detectedDependentPlugins,
};
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 !== process.env.MATOMO_CURRENT_PLUGIN
) {
detectedDependentPlugins.push(request);
}
callback(null, pluginExternals[request]);
return;
}
callback();
});
// disable asset size warnings
config.performance.hints(false);
},
};