Skip to content

Commit 738b7d2

Browse files
authored
Build visualizer output fix (#7701)
* Fixed treemap, treesun and treenet visualizer output * Enhance build documentation and optimize plugin usage for release builds
1 parent 49aaa95 commit 738b7d2

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.idea/
33
.vscode/
44
build
5-
tree*.html
5+
tree*.*.html
66
coverage
77
docs
88
examples/dist

build.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* - bundleState (unbundled, bundled)
1010
* Example: target:esm:release:bundled
1111
*
12-
* treemap - Enable treemap build visualization.
13-
* treenet - Enable treenet build visualization.
14-
* treesun - Enable treesun build visualization.
12+
* treemap - Enable treemap build visualization (release only).
13+
* treenet - Enable treenet build visualization (release only).
14+
* treesun - Enable treesun build visualization (release only).
1515
*/
1616

1717
import { execSync } from 'child_process';

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@
108108
"build:esm": "npm run build target:esm",
109109
"build:esm:release": "npm run build target:esm:release",
110110
"build:esm:debug": "npm run build target:esm:debug",
111-
"build:treemap": "npm run build target:umd treemap",
112-
"build:treenet": "npm run build target:umd treenet",
113-
"build:treesun": "npm run build target:umd treesun",
111+
"build:treemap": "npm run build target:release treemap",
112+
"build:treenet": "npm run build target:release treenet",
113+
"build:treesun": "npm run build target:release treesun",
114114
"build:sourcemaps": "npm run build -- -m",
115115
"watch": "npm run build -- -w",
116116
"watch:release": "npm run build target:release -- -w",

utils/rollup-build-target.mjs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,30 @@ function getJSCCOptions(buildType, isUMD) {
121121
}
122122

123123
/**
124+
* @param {string} type - The type of the output (e.g., 'umd', 'es').
124125
* @returns {OutputOptions['plugins']} - The output plugins.
125126
*/
126-
function getOutPlugins() {
127-
const plugins = [
128-
];
127+
function getOutPlugins(type) {
128+
const plugins = [];
129129

130130
if (process.env.treemap) {
131131
plugins.push(visualizer({
132-
filename: 'treemap.html',
132+
filename: `treemap.${type}.html`,
133133
brotliSize: true,
134134
gzipSize: true
135135
}));
136136
}
137137

138138
if (process.env.treenet) {
139139
plugins.push(visualizer({
140-
filename: 'treenet.html',
140+
filename: `treenet.${type}.html`,
141141
template: 'network'
142142
}));
143143
}
144144

145145
if (process.env.treesun) {
146146
plugins.push(visualizer({
147-
filename: 'treesun.html',
147+
filename: `treesun.${type}.html`,
148148
template: 'sunburst'
149149
}));
150150
}
@@ -155,6 +155,10 @@ function getOutPlugins() {
155155
/**
156156
* Build a target that Rollup is supposed to build (bundled and unbundled).
157157
*
158+
* For faster subsequent builds, the unbundled and release builds are cached in the HISTORY map to
159+
* be used for bundled and minified builds. They are stored in the HISTORY map with the key:
160+
* `<debug|release|profiler>-<umd|esm>-<bundled>`.
161+
*
158162
* @param {object} options - The build target options.
159163
* @param {'umd'|'esm'} options.moduleFormat - The module format.
160164
* @param {'debug'|'release'|'profiler'|'min'} options.buildType - The build type.
@@ -169,6 +173,9 @@ function buildTarget({ moduleFormat, buildType, bundleState, input = 'src/index.
169173
const isMin = buildType === 'min';
170174
const bundled = isUMD || isMin || bundleState === 'bundled';
171175

176+
const prefix = `${OUT_PREFIX[buildType]}`;
177+
const file = `${prefix}${isUMD ? '.js' : '.mjs'}`;
178+
172179
const targets = [];
173180

174181
// bundle from unbundled
@@ -187,7 +194,7 @@ function buildTarget({ moduleFormat, buildType, bundleState, input = 'src/index.
187194
sourcemap: isDebug && 'inline',
188195
name: 'pc',
189196
preserveModules: false,
190-
file: `${dir}/${OUT_PREFIX[buildType]}.mjs`
197+
file: `${dir}/${prefix}.mjs`
191198
}
192199
};
193200

@@ -211,8 +218,7 @@ function buildTarget({ moduleFormat, buildType, bundleState, input = 'src/index.
211218
],
212219
output: {
213220
banner: isUMD ? getBanner(BANNER[buildType]) : undefined,
214-
plugins: getOutPlugins(),
215-
file: `${dir}/${OUT_PREFIX[buildType]}${isUMD ? '.js' : '.mjs'}`
221+
file: `${dir}/${file}`
216222
},
217223
context: isUMD ? 'this' : undefined
218224
};
@@ -230,15 +236,15 @@ function buildTarget({ moduleFormat, buildType, bundleState, input = 'src/index.
230236
input,
231237
output: {
232238
banner: bundled ? getBanner(BANNER[buildType]) : undefined,
233-
plugins: isMin ? getOutPlugins() : undefined,
239+
plugins: buildType === 'release' ? getOutPlugins(isUMD ? 'umd' : 'es') : undefined,
234240
format: isUMD ? 'umd' : 'es',
235241
indent: '\t',
236242
sourcemap: bundled && isDebug && 'inline',
237243
name: 'pc',
238244
preserveModules: !bundled,
239245
preserveModulesRoot: !bundled ? rootDir : undefined,
240-
file: bundled ? `${dir}/${OUT_PREFIX[buildType]}${isUMD ? '.js' : '.mjs'}` : undefined,
241-
dir: !bundled ? `${dir}/${OUT_PREFIX[buildType]}` : undefined,
246+
file: bundled ? `${dir}/${file}` : undefined,
247+
dir: !bundled ? `${dir}/${prefix}` : undefined,
242248
entryFileNames: chunkInfo => `${chunkInfo.name.replace(/node_modules/g, 'modules')}.js`
243249
},
244250
plugins: [

0 commit comments

Comments
 (0)