diff --git a/public/app/angular/partials.ts b/public/app/angular/partials.ts index 32203a18f42..9a4703ba7e5 100644 --- a/public/app/angular/partials.ts +++ b/public/app/angular/partials.ts @@ -1,4 +1,34 @@ -let templates = (require as any).context('../', true, /\.html$/); -templates.keys().forEach((key: string) => { - templates(key); -}); +// TODO: Vite has no require.context support yet. Attempt at a workaround below. +// let templates = (require as any).context('../', true, /\.html$/); +// templates.keys().forEach((key: string) => { +// templates(key); +// }); + +// See vite.config.ts angularHtmlImport function for the code that _should_ assist with these templates. + +import 'app/angular/panel/partials/query_editor_row.html'; +import 'app/angular/partials/http_settings_next.html'; +import 'app/angular/partials/tls_auth_settings.html'; +import 'app/features/admin/partials/admin_home.html'; +import 'app/features/admin/partials/edit_org.html'; +import 'app/features/admin/partials/stats.html'; +import 'app/features/admin/partials/styleguide.html'; +import 'app/features/alerting/partials/alert_tab.html'; +import 'app/features/annotations/partials/event_editor.html'; +import 'app/partials/confirm_modal.html'; +import 'app/partials/modal.html'; +import 'app/partials/reset_password.html'; +import 'app/partials/signup_invited.html'; +import 'app/plugins/panel/graph/axes_editor.html'; +import 'app/plugins/panel/graph/tab_display.html'; +import 'app/plugins/panel/graph/tab_legend.html'; +import 'app/plugins/panel/graph/tab_series_overrides.html'; +import 'app/plugins/panel/graph/tab_thresholds.html'; +import 'app/plugins/panel/graph/tab_time_regions.html'; +import 'app/plugins/panel/graph/thresholds_form.html'; +import 'app/plugins/panel/graph/time_regions_form.html'; +import 'app/plugins/panel/heatmap/partials/axes_editor.html'; +import 'app/plugins/panel/heatmap/partials/display_editor.html'; +import 'app/plugins/panel/table-old/column_options.html'; +import 'app/plugins/panel/table-old/editor.html'; +import 'app/plugins/panel/table-old/module.html'; diff --git a/vite.config.ts b/vite.config.ts index af7f595a0d1..0b0b10d907f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,6 +5,28 @@ import { defineConfig } from 'vite'; const require = createRequire(import.meta.url); +// This is a Vite plugin for handling angular templates. +// https://vitejs.dev/guide/api-plugin.html#simple-examples + +// The webpack output from https://github.com/WearyMonkey/ngtemplate-loader looks like this: +// var code = "\n
\n\t
\n\t\t
\n\t\t
\n\n\t\t
\n\t\t\tAdd annotation\n\t\t\tEdit annotation\n\t\t
\n\n
{{ctrl.timeFormated}}
\n\t
\n\n\t
\n\t\t
\n\t\t\t
\n\t\t\t\tDescription\n\t\t\t\t\n\t\t\t
\n\n\t\t\t
\n\t\t\t\tTags\n\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tCancel\n\t\t\t
\n\t\t
\n\t
\n
\n"; +// Exports +// var _module_exports =code;; +// var path = 'public/app/features/annotations/partials/event_editor.html'; +// window.angular.module('ng').run(['$templateCache', function(c) { c.put(path, _module_exports) }]); +// module.exports = path; +function angularHtmlImport() { + return { + name: 'transform-angular-html', + transform(src, id) { + if (/^.*\.html$/g.test(id)) { + const result = `let path = '${id}'; angular.module('ng').run(['$templateCache', c => { c.put(path, \`${src}\`) }]); export default path;`; + return { code: result, map: null }; + } + }, + }; +} + // https://vitejs.dev/config/ export default defineConfig({ root: './public', @@ -21,7 +43,7 @@ export default defineConfig({ host: '0.0.0.0', port: 5173, }, - plugins: [react()], + plugins: [react(), angularHtmlImport()], optimizeDeps: { // fix for $ is not a function exclude: ['jquery'],