Files
mixtape/zero.Web.UI/vite.config.js
T

123 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-11-01 22:20:29 +01:00
const path = require('path');
2020-11-01 23:56:22 +01:00
const fs = require('fs');
2020-11-01 22:20:29 +01:00
const { createVuePlugin } = require('vite-plugin-vue2');
2021-07-22 15:47:40 +02:00
let loadedPlugins = JSON.parse(process.env.ZERO_PLUGINS || "[]");
if (!process.env.ZERO_PLUGINS)
{
loadedPlugins = ["../zero.Commerce/Plugin", "../zero.Stories/Plugin", "../zero.Forms/Plugin", "../../Laola/Laola.Backoffice/Plugin"];
}
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-05-08 15:20:23 +02:00
pluginFileContent += "import " + name + " from '" + alias + "/plugin.js';\n";
2020-11-01 23:56:22 +01:00
});
pluginFileContent += "export default [ " + pluginNames.join(', ') + " ];";
fs.writeFile(path.resolve(__dirname, 'app/core/plugins.js'), pluginFileContent, err =>
{
if (err)
{
console.error(err)
return
}
//file written successfully
})
2021-09-01 00:19:28 +02:00
const myPlugin = () => ({
name: 'configure-server',
configureServer(server)
{
var watcher = server.watcher;
watcher
.on('add', path => console.log(`watch: ${path}`));
var files = watcher.getWatched();
console.log('watcher:');
console.log(files);
// https://github.com/paulmillr/chokidar#api
//server.middlewares.use((req, res, next) =>
//{
// console.log(req.url);
// next();
// // custom handle request...
//})
}
})
2021-07-22 15:47:40 +02:00
/**
* @type {import('vite').UserConfig}
*/
let config = {
2021-05-08 15:20:23 +02:00
server: {
port: process.env.PORT || 3399,
2021-05-08 15:20:23 +02:00
cors: true
},
2021-09-01 00:19:28 +02:00
plugins: [createVuePlugin(), ...zeroPlugins, myPlugin()],
2020-11-01 22:20:29 +01:00
alias: {
2021-05-08 15:20:23 +02:00
'@zero': path.resolve(__dirname, 'app/'),
'zero': path.resolve(__dirname, 'app/'),
...pluginAliases,
2021-05-08 15:20:23 +02:00
'vue': 'vue/dist/vue.esm.js',
2021-08-28 19:38:26 +02:00
'tiptap': 'tiptap/dist/tiptap.esm.js',
'zerox': path.resolve(__dirname, 'app/zerox.js')
2020-12-30 13:21:35 +01:00
},
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-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
}
2020-12-30 13:21:35 +01:00
};
2021-09-01 00:19:28 +02:00
console.log('root: ' + config.root);
2021-07-22 15:47:40 +02:00
if (process.env.NODE_ENV === 'production')
{
config.base = '/zero/';
config.alias.tiptap = 'node_modules/tiptap/dist/tiptap.esm.js';
config.alias.underscore = 'node_modules/underscore/underscore-esm.js';
config.alias.axios = 'node_modules/axios/dist/axios.js';
config.alias.dayjs = 'node_modules/dayjs/esm/index.js';
}
2020-12-30 13:21:35 +01:00
export default config;