-
Notifications
You must be signed in to change notification settings - Fork 482
Expand file tree
/
Copy pathesbuild-configs.mjs
More file actions
135 lines (125 loc) · 3.6 KB
/
Copy pathesbuild-configs.mjs
File metadata and controls
135 lines (125 loc) · 3.6 KB
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import { wasmLoader } from 'esbuild-plugin-wasm';
import copy from 'esbuild-plugin-copy';
import {
externalChromeUrlsPlugin,
circularDependencyPlugin,
generateHtmlPlugin,
} from './esbuild-plugins.mjs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectRoot = path.normalize(path.join(__dirname, '..', '..'));
const isProduction = process.env.NODE_ENV === 'production';
const browserDistDir = 'dist/browser';
// Configuration shared by both node and browser builds
const baseConfig = {
bundle: true,
minify: isProduction,
absWorkingDir: projectRoot,
loader: {
'.png': 'file',
'.jpg': 'file',
'.svg': 'dataurl',
'.worker.js': 'file',
},
alias: {
'firefox-profiler': './src',
'firefox-profiler-res': './res',
},
};
// Common build configuration for node-based tools
export const nodeBaseConfig = {
...baseConfig,
platform: 'node',
target: 'node16',
splitting: false,
format: 'cjs',
bundle: true,
external: ['fs', 'path', 'crypto', 'zlib'],
plugins: [
wasmLoader({
mode: 'embedded',
}),
],
};
// Main bundle config
const templateHTML = fs.readFileSync(
path.join(projectRoot, 'res', 'index.html'),
'utf8'
);
export const mainBundleConfig = {
...baseConfig,
format: 'esm',
platform: 'browser',
target: browserslistToEsbuild(),
sourcemap: true,
splitting: true,
entryPoints: ['src/index.tsx'],
outdir: browserDistDir,
metafile: true,
publicPath: '/',
entryNames: '[name]-[hash]',
define: {
'process.env.L10N': process.env.L10N
? JSON.stringify(process.env.L10N)
: 'undefined',
AVAILABLE_STAGING_LOCALES: process.env.L10N
? JSON.stringify(fs.readdirSync('./locales'))
: 'undefined',
// no need to define NODE_ENV:
// esbuild automatically defines NODE_ENV based on the value for "minify"
},
external: ['zlib'],
plugins: [
externalChromeUrlsPlugin(),
circularDependencyPlugin(),
wasmLoader(),
copy({
resolveFrom: projectRoot,
assets: [
{ from: ['res/_headers'], to: [browserDistDir] },
{ from: ['res/_redirects'], to: [browserDistDir] },
{ from: ['res/contribute.json'], to: [browserDistDir] },
{ from: ['res/robots.txt'], to: [browserDistDir] },
{ from: ['res/service-worker-compat.js'], to: [browserDistDir] },
{ from: ['res/img/favicon.png'], to: [`${browserDistDir}/res/img`] },
{ from: ['docs-user/**/*'], to: [`${browserDistDir}/docs`] },
{ from: ['locales/**/*'], to: [`${browserDistDir}/locales`] },
],
}),
generateHtmlPlugin({
filename: 'index.html',
entryPoint: 'src/index.tsx',
templateHTML,
}),
],
};
// Photon styling build configuration
const photonTemplateHTML = fs.readFileSync(
path.join(projectRoot, 'res', 'photon', 'index.html'),
'utf8'
);
export const photonConfig = {
...baseConfig,
format: 'esm',
platform: 'browser',
target: browserslistToEsbuild(),
sourcemap: true,
publicPath: '/photon/',
entryPoints: ['res/photon/index.js'],
outdir: `${browserDistDir}/photon`,
metafile: true,
plugins: [
generateHtmlPlugin({
filename: 'index.html',
entryPoint: 'res/photon/index.js',
templateHTML: photonTemplateHTML,
}),
],
};