【metabase】 01-metabase开发环境搭建

1. metabase技术和框架

  • 前端: React+Redux+D3(图表工具),使用webpack构建
  • 后端:Clojure + RING(中间件) + Compojure(路由框架) + Toucan(ORM框架)

2. 准备

3. 搭建步骤

3.1 后端

  • 安装插件 cursive ,然后重启IDEA
  • 将metabase-0.39.4整个目录引入到idea中,然后在Terminal中执行命令lein run启动
  • 默认配置参考文件:metabase-0.39.4/src/metabase/config.clj

3.2 前端

  • 将整个项目引入到VS Code中,然后执行命令yarn run build-hot进行启动
  • 由于前端内容较多,编译较慢,可以参考https://www.freesion.com/article/2263192982/进行优化
    优化后webpack.config.js配置如下
/* eslint-env node */
/* eslint-disable import/no-commonjs */
 
require("babel-register");
require("babel-polyfill");
 
var webpack = require('webpack');
var path = require("path");
 
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
var UnusedFilesWebpackPlugin = require("unused-files-webpack-plugin").default;
var BannerWebpackPlugin = require('banner-webpack-plugin');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin')
 
var fs = require('fs');
 
var chevrotain = require("chevrotain");
var allTokens = require("./frontend/src/metabase/lib/expressions/tokens").allTokens;
 
var SRC_PATH = __dirname + '/frontend/src/metabase';
var LIB_SRC_PATH = __dirname + '/frontend/src/metabase-lib';
var TEST_SUPPORT_PATH = __dirname + '/frontend/test/__support__';
var BUILD_PATH = __dirname + '/resources/frontend_client';
 
// default NODE_ENV to development
var NODE_ENV = process.env["NODE_ENV"] || "development";
 
// Babel:
var BABEL_CONFIG = {
    cacheDirectory: process.env.BABEL_DISABLE_CACHE ? null : ".babel_cache"
};
 
var CSS_CONFIG = {
    localIdentName: NODE_ENV !== "production" ?
        "[name]__[local]___[hash:base64:5]" :
        "[hash:base64:5]",
    url: false, // disabled because we need to use relative url()
    importLoaders: 1
}
 
var config = module.exports = {
    context: SRC_PATH,
 
    // output a bundle for the app JS and a bundle for styles
    // eventually we should have multiple (single file) entry points for various pieces of the app to enable code splitting
    entry: {
        "app-main": './app-main.js',
        // "app-public": './app-public.js',
        // "app-embed": './app-embed.js',
        styles: './css/index.css',
    },
 
    // output to "dist"
    output: {
        path: BUILD_PATH + '/app/dist',
        // NOTE: the filename on disk won't include "?[chunkhash]" but the URL in index.html generated by HtmlWebpackPlugin will:
        filename: '[name].bundle.js?[hash]',
        publicPath: 'app/dist/'
    },
 
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: [
                    { loader: "babel-loader", options: BABEL_CONFIG }
                ]
            },
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules|\.spec\.js/,
                use: [
                    { loader: "eslint-loader" }
                ]
            },
            {
                test: /\.(eot|woff2?|ttf|svg|png)$/,
                use: [
                    { loader: "file-loader" }
                ]
            },
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: [
                        { loader: "css-loader", options: CSS_CONFIG },
                        { loader: "postcss-loader" }
                    ]
                })
            }
            ]
    },
    resolve: {
        extensions: [".webpack.js", ".web.js", ".js", ".jsx", ".css"],
        alias: {
            'metabase':             SRC_PATH,
            'metabase-lib':         LIB_SRC_PATH,
            '__support__':          TEST_SUPPORT_PATH,
            'style':                SRC_PATH + '/css/core/index',
            'ace':                  __dirname + '/node_modules/ace-builds/src-min-noconflict',
        },
 
    },
 
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor'],   
            filename: 'vendor.min.js' ,  //利用浏览器缓存      
            minChunks (module) {
                return module.context && module.context.indexOf('node_modules') >= 0
            }
        }),
        new webpack.optimize.CommonsChunkPlugin({ 
            name: 'manifest' //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
        }),
        new UnusedFilesWebpackPlugin({
            globOptions: {
                ignore: [
                   "**/types.js",
                    "**/types/*.js",
                    "**/*.spec.*",
                    "**/__support__/*.js",
                    "**/__mocks__/*.js*",
                    "internal/lib/components-node.js"
                ]
            }
        }),
        // Extracts initial CSS into a standard stylesheet that can be loaded in parallel with JavaScript
        // NOTE: the filename on disk won't include "?[chunkhash]" but the URL in index.html generated by HtmlWebpackPlugin will:
        new ExtractTextPlugin({
            filename: '[name].bundle.css?[contenthash]'
        }),
        new HtmlWebpackPlugin({
            filename: '../../index.html',
            chunksSortMode: 'manual',
            chunks: ["manifest","vendor", "styles", "app-main"],
            template: __dirname + '/resources/frontend_client/index_template.html',
            inject: 'head',
            alwaysWriteToDisk: true,
        }),
        // new HtmlWebpackPlugin({
        //     filename: '../../public.html',
        //     chunksSortMode: 'manual',
        //     chunks: ["vendor", "styles", "app-public"],
        //     template: __dirname + '/resources/frontend_client/index_template.html',
        //     inject: 'head',
        //     alwaysWriteToDisk: true,
        // }),
        // new HtmlWebpackPlugin({
        //     filename: '../../embed.html',
        //     chunksSortMode: 'manual',
        //     chunks: ["vendor", "styles", "app-embed"],
        //     template: __dirname + '/resources/frontend_client/index_template.html',
        //     inject: 'head',
        //     alwaysWriteToDisk: true,
        // }),
        new HtmlWebpackHarddiskPlugin({
            outputPath: __dirname + '/resources/frontend_client/app/dist'
        }),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify(NODE_ENV)
            }
        }),
        new BannerWebpackPlugin({
            chunks: {
                'app-main': {
                    beforeContent: "/*\n* This file is subject to the terms and conditions defined in\n * file 'LICENSE.txt', which is part of this source code package.\n */\n",
                },
                // 'app-public': {
                //     beforeContent: "/*\n* This file is subject to the terms and conditions defined in\n * file 'LICENSE.txt', which is part of this source code package.\n */\n",
                // },
                // 'app-embed': {
                //     beforeContent: "/*\n* This file is subject to the terms and conditions defined in\n * file 'LICENSE-EMBEDDING.txt', which is part of this source code package.\n */\n",
                // },
            }
        }),
    ]
};
 
if (NODE_ENV === "hot") {
    // suffixing with ".hot" allows us to run both `yarn run build-hot` and `yarn run test` or `yarn run test-watch` simultaneously
    config.output.filename = "[name].hot.bundle.js?[hash]";
 
    // point the publicPath (inlined in index.html by HtmlWebpackPlugin) to the hot-reloading server
    config.output.publicPath = "http://localhost:8080/" + config.output.publicPath;
 
    config.module.rules.unshift({
        test: /\.jsx$/,
        exclude: /node_modules/,
        use: [
            // NOTE Atte Keinänen 10/19/17: We are currently sticking to an old version of react-hot-loader
            // because newer versions would require us to upgrade to react-router v4 and possibly deal with
            // asynchronous route issues as well. See https://github.com/gaearon/react-hot-loader/issues/249
            { loader: 'react-hot-loader' },
            { loader: 'babel-loader', options: BABEL_CONFIG }
        ]
    });
 
    // disable ExtractTextPlugin
    config.module.rules[config.module.rules.length - 1].use = [
        { loader: "style-loader" },
        { loader: "css-loader", options: CSS_CONFIG },
        { loader: "postcss-loader" }
    ]
 
    config.devServer = {
        hot: true,
        inline: true,
        contentBase: "frontend",
        headers: {
            'Access-Control-Allow-Origin': '*'
        }
        // if webpack doesn't reload UI after code change in development
        // watchOptions: {
        //     aggregateTimeout: 300,
        //     poll: 1000
        // }
        // if you want to reduce stats noise
        // stats: 'minimal' // values: none, errors-only, minimal, normal, verbose
    };
 
    config.plugins.unshift(
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin()
    );
}
 
if (NODE_ENV !== "production") {
    // replace minified files with un-minified versions
    for (var name in config.resolve.alias) {
        var minified = config.resolve.alias[name];
        var unminified = minified.replace(/[.-\/]min\b/g, '');
        if (minified !== unminified && fs.existsSync(unminified)) {
            config.resolve.alias[name] = unminified;
        }
    }
 
 
    // enable "cheap" source maps in hot or watch mode since re-build speed overhead is < 1 second
    //config.devtool = "cheap-module-source-map";
     config.devtool = "eval-source-map";
    // works with breakpoints
   // config.devtool = "inline-source-map"
 
    // helps with source maps
    config.output.devtoolModuleFilenameTemplate = '[absolute-resource-path]';
    config.output.pathinfo = true;
} else {
    config.plugins.push(new UglifyJSPlugin({
        uglifyOptions: {
            mangle: {
                // this is required to ensure we don't minify Chevrotain token identifiers
                // https://github.com/SAP/chevrotain/tree/master/examples/parser/minification
                except: allTokens.map(function(currTok) {
                    return chevrotain.tokenName(currTok);
                })
            }
        }
    }))
 
    config.devtool = "source-map";
}

详情说明请参考源文件

3.3 访问

前后端都启动后,默认可以通过http://localhost:3000进行访问

3.4 常用命令

命令说明
打开REPL环境lein repl
前端编译yarn build
前端热部署yarn build-hot
后端运行lein run
项目打包,包含依赖项。得到jar后就跟平常的jar没有区别lein uberjar
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Metabase是一种开源的业务智能(BI)工具,具备丰富的数据分析和可视化功能。作为一个强大的BI工具,Metabase也提供了二次开发的功能,使用户可以根据自己的需求进行定制和扩展。 Metabase二次开发工具包括以下几个方面: 1. Metabase API:Metabase提供了强大的API,可以通过编程方式对Metabase进行定制和扩展。开发人员可以使用API来获取数据、创建和修改问题(queries)、设置图表和仪表盘等。通过使用API,用户可以更精确地控制Metabase的功能。 2. 使用自定义查询:Metabase支持使用SQL进行查询,用户可以利用自己熟悉的数据库查询语言进行复杂查询。通过编写自定义查询语句,用户可以在Metabase中实现更复杂的数据分析和报表需求。 3. 自定义数据可视化:Metabase提供了多种图表类型和可视化效果,但有时可能无法完全满足用户的需求。用户可以通过定制CSS来自定义图表的样式和外观,以实现更好的数据可视化效果。 4. 自定义插件和扩展:Metabase还支持开发者通过创建插件或扩展,来增加新的功能和特性。通过插件机制,用户可以将自己开发的功能集成到Metabase中,以满足特定的业务需求。 Metabase的二次开发工具使开发人员能够根据具体业务需求对Metabase进行定制和扩展。无论是通过API进行编程,使用自定义查询语句,定制数据可视化,还是通过插件和扩展添加新功能,Metabase都提供了丰富的扩展性和灵活性,使用户能够深度定制、个性化地使用Metabase进行数据分析和可视化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值