Skip to content

Commit 8b8219b

Browse files
authored
[Chore] esbuild website to speedup netlify build (#2904)
1 parent 803b2f5 commit 8b8219b

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

website/esbuild.config.mjs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ const RESOLVE_LOCAL_ALIASES = {
2727
echarts: `${NODE_MODULES_DIR}/echarts`
2828
};
2929

30+
// Add kepler.gl submodule aliases
31+
const workspaces = WebsitePackage.workspaces;
32+
workspaces.forEach(workspace => {
33+
// workspace = "./src/types", "./src/constants", etc
34+
const moduleName = workspace.split('/').pop();
35+
RESOLVE_LOCAL_ALIASES[`@kepler.gl/${moduleName}`] = join(SRC_DIR, `${moduleName}/src`);
36+
});
37+
3038
const config = {
3139
platform: 'browser',
3240
format: 'iife',
@@ -41,7 +49,7 @@ const config = {
4149
entryPoints: [
4250
'src/main.js',
4351
],
44-
outdir: 'dist',
52+
outfile: 'dist/bundle.js',
4553
bundle: true,
4654
define: {
4755
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'production'),
@@ -74,13 +82,48 @@ function openURL(url) {
7482
}
7583
}
7684

85+
function logError(msg) {
86+
console.log('\x1b[31m%s\x1b[0m', msg);
87+
}
88+
89+
function logInstruction(msg) {
90+
console.log('\x1b[36m%s\x1b[0m', msg);
91+
}
92+
93+
function validateEnvVariable(variable, instruction) {
94+
if (!process.env[variable]) {
95+
logError(`Error! ${variable} is not defined`);
96+
logInstruction(`Make sure to run "export ${variable}=<token>" before deploy the website`);
97+
logInstruction(instruction);
98+
throw new Error(`Missing ${variable}`);
99+
}
100+
}
101+
77102
(async () => {
78103
if (args.includes('--build')) {
104+
// Validate environment variables before production build
105+
const ENV_VARIABLES_WITH_INSTRUCTIONS = {
106+
MapboxAccessToken: 'Get your Mapbox token at https://www.mapbox.com/help/how-access-tokens-work/',
107+
DropboxClientId: 'Get your Dropbox key at https://www.dropbox.com/developers',
108+
MapboxExportToken: 'Get your Mapbox token at https://www.mapbox.com/help/how-access-tokens-work/',
109+
CartoClientId: 'Get your CARTO client id',
110+
FoursquareClientId: 'Get your Foursquare client id',
111+
FoursquareDomain: 'Set your Foursquare domain',
112+
FoursquareAPIURL: 'Set your Foursquare API URL',
113+
FoursquareUserMapsURL: 'Set your Foursquare User Maps URL'
114+
};
115+
116+
// Validate all environment variables
117+
Object.entries(ENV_VARIABLES_WITH_INSTRUCTIONS).forEach(([variable, instruction]) => {
118+
validateEnvVariable(variable, instruction);
119+
});
120+
79121
await esbuild
80122
.build({
81123
...config,
82124
minify: true,
83-
sourcemap: false
125+
sourcemap: false,
126+
alias: RESOLVE_LOCAL_ALIASES
84127
})
85128
.catch(e => {
86129
console.error(e);

website/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
"main": "dist/index.js",
77
"version": "0.0.1",
88
"scripts": {
9+
"dev": "node esbuild.config.mjs --start",
10+
"esbuild": "yarn build-clean && yarn build-static && node esbuild.config.mjs --build",
911
"start": "webpack serve --mode development --env prod --static-directory ./src/static --progress --open",
1012
"start-prod": "webpack serve --mode production --env prod --static-directory ./src/static --progress --open",
1113
"build-clean": "rm -rf ./dist && mkdir dist",
1214
"build-static": "cp -r ./src/static/* dist",
1315
"build-script": "NODE_OPTIONS=--openssl-legacy-provider webpack --mode production --env prod",
14-
"build": "yarn build-clean && yarn build-static && yarn build-script",
16+
"build": "yarn build-clean && yarn build-static && yarn esbuild",
1517
"lint": "eslint src"
1618
},
1719
"dependencies": {

website/src/static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
});
4242
</script>
4343

44+
<link rel="stylesheet" href="/bundle.css">
4445
<style>
4546
body {margin: 0; padding: 0; overflow-x: hidden;}
4647
</style>

0 commit comments

Comments
 (0)