forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.static-viz.config.js
172 lines (164 loc) · 4.8 KB
/
webpack.static-viz.config.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const YAML = require("json-to-pretty-yaml");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
const { StatsWriterPlugin } = require("webpack-stats-plugin");
const ASSETS_PATH = __dirname + "/resources/frontend_client/app/assets";
const SRC_PATH = __dirname + "/frontend/src/metabase";
const BUILD_PATH = __dirname + "/resources/frontend_client";
const CLJS_SRC_PATH = __dirname + "/target/cljs_release";
const CLJS_SRC_PATH_DEV = __dirname + "/target/cljs_dev";
const LIB_SRC_PATH = __dirname + "/frontend/src/metabase-lib";
const TYPES_SRC_PATH = __dirname + "/frontend/src/metabase-types";
const SDK_SRC_PATH = __dirname + "/enterprise/frontend/src/embedding-sdk";
const WEBPACK_BUNDLE = process.env.WEBPACK_BUNDLE || "development";
const devMode = WEBPACK_BUNDLE !== "production";
module.exports = env => {
return {
mode: "production",
context: SRC_PATH,
performance: {
hints: false,
},
entry: {
"lib-static-viz": {
import: "./static-viz/index.js",
library: {
name: "StaticViz",
type: "var",
},
},
},
output: {
path: BUILD_PATH + "/app/dist",
filename: "[name].bundle.js",
publicPath: "/app/dist",
globalObject: "{}",
},
module: {
rules: [
{
test: /\.css$/i,
use: "null-loader",
},
{
test: /\.(tsx?|jsx?)$/,
exclude: /node_modules|cljs|css\/core\/fonts\.styled\.ts/,
use: [
{
loader: "swc-loader",
options: {
jsc: {
loose: true,
transform: {
react: {
runtime: "automatic",
refresh: false,
},
},
parser: {
syntax: "typescript",
tsx: true,
},
experimental: {
plugins: [["@swc/plugin-emotion", { sourceMap: devMode }]],
},
},
sourceMaps: true,
minify: false, // produces same bundle size, but cuts 1s locally
env: {
targets: ["defaults"],
},
},
},
],
},
{
test: /\.svg/,
type: "asset/source",
resourceQuery: /source/, // *.svg?source
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: /component/, // *.svg?component
use: [
{
loader: "@svgr/webpack",
options: {
ref: true,
},
},
],
},
{
test: /\.svg$/,
type: "asset/resource",
resourceQuery: { not: [/component|source/] },
},
],
},
resolve: {
extensions: [".webpack.js", ".web.js", ".js", ".jsx", ".ts", ".tsx"],
alias: {
assets: ASSETS_PATH,
metabase: SRC_PATH,
cljs: devMode ? CLJS_SRC_PATH_DEV : CLJS_SRC_PATH,
"metabase-lib": LIB_SRC_PATH,
"metabase-types": TYPES_SRC_PATH,
"embedding-sdk": SDK_SRC_PATH,
"process/browser": require.resolve("process/browser"),
},
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer/"),
process: require.resolve("process/browser"),
},
},
optimization: {
minimize: false,
minimizer: [
new TerserPlugin({
minify: TerserPlugin.swcMinify,
}),
],
},
plugins: [
new webpack.EnvironmentPlugin({
EMBEDDING_SDK_VERSION: null,
IS_EMBEDDING_SDK_BUILD: false,
}),
new webpack.NormalModuleReplacementPlugin(
/node_modules\/@reduxjs\/toolkit\/.*\/process$/,
"process/browser",
),
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
new StatsWriterPlugin({
stats: {
modules: true,
assets: false,
nestedModules: false,
reasons: false,
excludeModules: [/node_modules/],
},
filename: "../../../../.github/static-viz-sources.yaml",
transform: stats =>
YAML.stringify({
static_viz: stats.modules
.filter(
module =>
module.type !== "hidden modules" &&
module.moduleType !== "runtime" &&
module.nameForCondition != null,
)
.map(module =>
module.nameForCondition.replace(`${__dirname}/`, ""),
),
}),
}),
],
};
};