File size: 1,773 Bytes
db5855f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import react from '@vitejs/plugin-react';
import { join, resolve } from 'path';
import { URL } from 'url';
import { defineConfig, loadEnv } from 'vite';
import svgr from 'vite-plugin-svgr';

import { collectNotebooksFilesPlugin } from './src/shared/collect-notebooks-files-plugin.js';

const ENV_DIR = join(__dirname, 'vite-env');

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const viteEnv = loadEnv(mode, ENV_DIR);

  return {
    plugins: [react(), svgr(), collectNotebooksFilesPlugin()],
    base: '/openvino_notebooks/',
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        '@assets': resolve(__dirname, './src/assets'),
        '@components': resolve(__dirname, './src/components'),
        '@spark-design': resolve(__dirname, './src/@spark-design'),
      },
    },
    build: {
      outDir: join('dist', 'openvino_notebooks'),
      modulePreload: {
        polyfill: false,
      },
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'index.html'),
          embedded: resolve(__dirname, 'embedded.html'),
        },
        output: {
          entryFileNames({ name, isEntry }) {
            if (name === 'embedded' && isEntry) {
              return 'assets/[name].js';
            }
            return 'assets/[name]-[hash].js';
          },
        },
      },
    },
    esbuild: {
      supported: {
        'top-level-await': true,
      },
    },
    envDir: ENV_DIR,
    experimental: {
      renderBuiltUrl(filename: string, { hostId }: { hostId: string }) {
        if (hostId === 'embedded.html') {
          return new URL(filename, viteEnv.VITE_APP_LOCATION).toString();
        }
      },
    },
  };
});