2020-11-01 22:20:29 +01:00
|
|
|
const path = require('path');
|
2020-11-01 23:56:22 +01:00
|
|
|
const fs = require('fs');
|
2021-12-06 15:06:38 +01:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2021-12-14 14:21:48 +01:00
|
|
|
import pluginRewriteAll from 'vite-plugin-rewrite-all'
|
2020-11-01 22:20:29 +01:00
|
|
|
|
2021-07-22 15:47:40 +02:00
|
|
|
let loadedPlugins = JSON.parse(process.env.ZERO_PLUGINS || "[]");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!process.env.ZERO_PLUGINS)
|
|
|
|
|
{
|
2021-11-29 00:38:55 +01:00
|
|
|
//loadedPlugins = ["../zero.Commerce/Plugin", "../zero.Stories/Plugin", "../zero.Forms/Plugin", "../../Laola/Laola.Backoffice/Plugin"];
|
2022-01-05 16:46:32 +01:00
|
|
|
loadedPlugins = ["../plugins/zero.Commerce/Backoffice/Plugin", "../../Laola/Laola.Backoffice/Plugin"]
|
2021-12-29 01:25:35 +01:00
|
|
|
//loadedPlugins = [];
|
2021-07-22 15:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-01 22:20:29 +01:00
|
|
|
let zeroPlugins = [];
|
2020-11-01 23:56:22 +01:00
|
|
|
|
|
|
|
|
let pluginFileContent = '';
|
|
|
|
|
let pluginAliases = {};
|
|
|
|
|
let pluginNames = [];
|
|
|
|
|
let idx = 0;
|
|
|
|
|
|
2020-12-02 22:25:20 +01:00
|
|
|
loadedPlugins.forEach(pluginPath =>
|
2020-11-01 23:56:22 +01:00
|
|
|
{
|
2020-12-02 22:25:20 +01:00
|
|
|
const viteConfigPath = pluginPath + "/vite.plugin.js";
|
|
|
|
|
const pluginConfig = require(viteConfigPath);
|
2021-05-08 15:20:23 +02:00
|
|
|
const resolvedPluginConfig = pluginConfig();
|
|
|
|
|
zeroPlugins.push(resolvedPluginConfig);
|
2020-11-01 23:56:22 +01:00
|
|
|
|
|
|
|
|
const name = 'zeroPlugin' + idx;
|
2021-05-08 15:20:23 +02:00
|
|
|
const alias = '@zeroplugin' + (idx++);
|
2020-12-02 22:25:20 +01:00
|
|
|
pluginAliases[alias] = path.resolve(__dirname, pluginPath);
|
2021-05-08 15:20:23 +02:00
|
|
|
|
|
|
|
|
if (typeof resolvedPluginConfig.alias === 'object')
|
|
|
|
|
{
|
|
|
|
|
for (const key in resolvedPluginConfig.alias)
|
|
|
|
|
{
|
|
|
|
|
pluginAliases[key] = resolvedPluginConfig.alias[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-01 23:56:22 +01:00
|
|
|
pluginNames.push(name);
|
2021-12-29 01:25:35 +01:00
|
|
|
pluginFileContent += "import " + name + " from '" + alias + "/plugin';\n";
|
2020-11-01 23:56:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pluginFileContent += "export default [ " + pluginNames.join(', ') + " ];";
|
|
|
|
|
|
2021-12-29 01:25:35 +01:00
|
|
|
fs.writeFile(path.resolve(__dirname, 'app/plugins.generated.ts'), pluginFileContent, err =>
|
2020-11-01 23:56:22 +01:00
|
|
|
{
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
console.error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//file written successfully
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-06 15:06:38 +01:00
|
|
|
let config = defineConfig({
|
2021-05-08 15:20:23 +02:00
|
|
|
server: {
|
2021-11-12 15:16:48 +01:00
|
|
|
port: process.env.PORT || 3399,
|
2021-12-07 15:59:29 +01:00
|
|
|
cors: true,
|
|
|
|
|
proxy: {
|
|
|
|
|
'/zero/api': {
|
2022-01-05 16:46:32 +01:00
|
|
|
target: 'http://localhost:2310',
|
2021-12-07 15:59:29 +01:00
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
ws: false
|
2021-12-16 13:55:09 +01:00
|
|
|
},
|
|
|
|
|
'/uploads': {
|
2022-01-05 16:46:32 +01:00
|
|
|
target: 'http://localhost:2310',
|
2021-12-16 13:55:09 +01:00
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
ws: false
|
2021-12-07 15:59:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-05-08 15:20:23 +02:00
|
|
|
},
|
2021-12-09 14:18:38 +01:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
2021-12-29 01:25:35 +01:00
|
|
|
vue: '@vue/compat',
|
2021-12-29 11:00:14 +01:00
|
|
|
zero: path.resolve(__dirname, 'app'),
|
2021-12-29 01:25:35 +01:00
|
|
|
...pluginAliases,
|
2021-12-09 14:18:38 +01:00
|
|
|
}
|
|
|
|
|
},
|
2021-12-14 14:21:48 +01:00
|
|
|
plugins: [
|
|
|
|
|
pluginRewriteAll(),
|
|
|
|
|
vue({
|
|
|
|
|
template: {
|
|
|
|
|
compilerOptions: {
|
|
|
|
|
compatConfig: {
|
|
|
|
|
MODE: 2
|
|
|
|
|
}
|
2021-12-09 14:18:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-14 14:21:48 +01:00
|
|
|
}),
|
|
|
|
|
...zeroPlugins
|
|
|
|
|
],
|
2021-05-08 15:20:23 +02:00
|
|
|
build: {
|
2021-07-22 15:47:40 +02:00
|
|
|
manifest: true,
|
|
|
|
|
outDir: 'dist/zero',
|
|
|
|
|
minify: false,
|
|
|
|
|
terserOptions: {
|
|
|
|
|
compress: false
|
2021-05-08 15:20:23 +02:00
|
|
|
},
|
2021-12-07 15:59:29 +01:00
|
|
|
//alias: {
|
|
|
|
|
// 'tiptap': 'tiptap/dist/tiptap.esm.js',
|
|
|
|
|
//},
|
2021-07-22 15:47:40 +02:00
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
format: 'es',
|
|
|
|
|
entryFileNames: `[name].js`,
|
|
|
|
|
chunkFileNames: `[name].js`,
|
|
|
|
|
assetFileNames: `[name].[ext]`
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-08 15:20:23 +02:00
|
|
|
}
|
2021-12-06 15:06:38 +01:00
|
|
|
});
|
2020-12-30 13:21:35 +01:00
|
|
|
|
2021-12-07 01:11:18 +01:00
|
|
|
//console.log('root: ' + config.root);
|
2021-09-01 00:19:28 +02:00
|
|
|
|
2021-07-22 15:47:40 +02:00
|
|
|
if (process.env.NODE_ENV === 'production')
|
|
|
|
|
{
|
|
|
|
|
config.base = '/zero/';
|
2021-12-07 15:59:29 +01:00
|
|
|
//config.alias.tiptap = 'node_modules/tiptap/dist/tiptap.esm.js';
|
2021-07-22 15:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 13:21:35 +01:00
|
|
|
export default config;
|