Skip to content

Commit

Permalink
Build frontend visualizations as umd library #4
Browse files Browse the repository at this point in the history
  • Loading branch information
hotlong committed Jul 27, 2023
1 parent 6c03f36 commit d9382f9
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ yarn build-static-viz
yarn build-viz
```

Test frontent

```
npx serve resources/frontend_client/
```

Copy to Steedos Analytics

```
Expand Down
99 changes: 99 additions & 0 deletions frontend/src/metabase/lib-viz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// /*
// * This file is subject to the terms and conditions defined in
// * file 'LICENSE-EMBEDDING.txt', which is part of this source code package.
// */

// import "regenerator-runtime/runtime";

// // Use of classList.add and .remove in Background and FitViewPort Hocs requires
// // this polyfill so that those work in older browsers
// import "classlist-polyfill";

// import "number-to-locale-string";

// // This is conditionally aliased in the webpack config.
// // If EE isn't enabled, it loads an empty file.
// // Should be imported before any other metabase import
// import "ee-overrides"; // eslint-disable-line import/no-unresolved, import/no-duplicates

// // If enabled this monkeypatches `t` and `jt` to return blacked out
// // strings/elements to assist in finding untranslated strings.
// import "metabase/lib/i18n-debug";

// // set the locale before loading anything else
// import "metabase/lib/i18n";

// // NOTE: why do we need to load this here?
// import "metabase/lib/colors";

// // NOTE: this loads all builtin plugins
// import "metabase/plugins/builtin";

// // router
// import { useRouterHistory } from "react-router";
// import { createHistory } from "history";

// import { refreshSiteSettings } from "metabase/redux/settings";
// import { initializeEmbedding } from "metabase/lib/embed";
// import api from "metabase/lib/api";
// import MetabaseSettings from "metabase/lib/settings";
// import registerVisualizations from "metabase/visualizations/register";
// import { PLUGIN_APP_INIT_FUCTIONS } from "metabase/plugins";

// import { getStore } from "./store";

// // remove trailing slash
// const BASENAME = window.MetabaseRoot.replace(/\/+$/, "");

// api.basename = BASENAME;

// // eslint-disable-next-line react-hooks/rules-of-hooks
// const browserHistory = useRouterHistory(createHistory)({
// basename: BASENAME,
// });

// function _init(reducers, callback) {
// const store = getStore(reducers, browserHistory);

// let root;

// registerVisualizations();

// initializeEmbedding(store);

// store.dispatch(refreshSiteSettings());

// PLUGIN_APP_INIT_FUCTIONS.forEach(init => init({ root }));

// window.Metabase = window.Metabase || {};
// window.Metabase.store = store;
// window.Metabase.settings = MetabaseSettings;

// if (callback) {
// callback(store);
// }
// }

// export function init(...args) {
// if (document.readyState !== "loading") {
// _init(...args);
// } else {
// document.addEventListener("DOMContentLoaded", () => _init(...args));
// }
// }

import { init } from "./app";

import reducersPublic from "./reducers-public";

import Visualization from "./visualizations/components/Visualization";

const getRoutes = () => {
return;
};

export const initApp = callback => {
init(reducersPublic, getRoutes, callback);
};

export { Visualization };
18 changes: 15 additions & 3 deletions webpack.viz.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const SRC_PATH = __dirname + "/frontend/src/metabase";
const BUILD_PATH = __dirname + "/resources/frontend_client";
const CLJS_SRC_PATH = __dirname + "/frontend/src/cljs_release";
const LIB_SRC_PATH = __dirname + "/frontend/src/metabase-lib";
const ENTERPRISE_SRC_PATH =
__dirname + "/enterprise/frontend/src/metabase-enterprise";

const WEBPACK_BUNDLE = process.env.WEBPACK_BUNDLE || "development";
const devMode = WEBPACK_BUNDLE !== "production";
Expand All @@ -24,7 +26,7 @@ const CSS_CONFIG = {
};

module.exports = env => {
const shouldDisableMinimization = env.WEBPACK_WATCH === true;
const shouldDisableMinimization = devMode || env.WEBPACK_WATCH === true;

return {
mode: "production",
Expand All @@ -36,9 +38,9 @@ module.exports = env => {

entry: {
"lib-viz": {
import: "./visualizations/components/Visualization/index.ts",
import: "./lib-viz.js",
library: {
name: "Visualizations",
name: "Visualization",
type: "var",
},
},
Expand All @@ -47,6 +49,8 @@ module.exports = env => {
output: {
path: BUILD_PATH + "/app/dist",
filename: "[name].bundle.js",
library: 'Visualization',
libraryTarget: 'umd',
},

module: {
Expand Down Expand Up @@ -100,6 +104,14 @@ module.exports = env => {
cljs: CLJS_SRC_PATH,
"metabase-lib": LIB_SRC_PATH,
style: SRC_PATH + "/css/core/index",
ace: __dirname + "/node_modules/ace-builds/src-min-noconflict", "ee-plugins":
process.env.MB_EDITION === "ee"
? ENTERPRISE_SRC_PATH + "/plugins"
: SRC_PATH + "/lib/noop",
"ee-overrides":
process.env.MB_EDITION === "ee"
? ENTERPRISE_SRC_PATH + "/overrides"
: SRC_PATH + "/lib/noop",
},
},
optimization: {
Expand Down

0 comments on commit d9382f9

Please sign in to comment.