Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.idea/
.vscode/
build
tree*.html
tree*.*.html
coverage
docs
examples/dist
Expand Down
6 changes: 3 additions & 3 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* - bundleState (unbundled, bundled)
* Example: target:esm:release:bundled
*
* treemap - Enable treemap build visualization.
* treenet - Enable treenet build visualization.
* treesun - Enable treesun build visualization.
* treemap - Enable treemap build visualization (release only).
* treenet - Enable treenet build visualization (release only).
* treesun - Enable treesun build visualization (release only).
*/

import { execSync } from 'child_process';
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
"build:esm": "npm run build target:esm",
"build:esm:release": "npm run build target:esm:release",
"build:esm:debug": "npm run build target:esm:debug",
"build:treemap": "npm run build target:umd treemap",
"build:treenet": "npm run build target:umd treenet",
"build:treesun": "npm run build target:umd treesun",
"build:treemap": "npm run build target:release treemap",
"build:treenet": "npm run build target:release treenet",
"build:treesun": "npm run build target:release treesun",
"build:sourcemaps": "npm run build -- -m",
"watch": "npm run build -- -w",
"watch:release": "npm run build target:release -- -w",
Expand Down
30 changes: 18 additions & 12 deletions utils/rollup-build-target.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,30 @@ function getJSCCOptions(buildType, isUMD) {
}

/**
* @param {string} type - The type of the output (e.g., 'umd', 'es').
* @returns {OutputOptions['plugins']} - The output plugins.
*/
function getOutPlugins() {
const plugins = [
];
function getOutPlugins(type) {
const plugins = [];

if (process.env.treemap) {
plugins.push(visualizer({
filename: 'treemap.html',
filename: `treemap.${type}.html`,
brotliSize: true,
gzipSize: true
}));
}

if (process.env.treenet) {
plugins.push(visualizer({
filename: 'treenet.html',
filename: `treenet.${type}.html`,
template: 'network'
}));
}

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

const prefix = `${OUT_PREFIX[buildType]}`;
const file = `${prefix}${isUMD ? '.js' : '.mjs'}`;

const targets = [];

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

Expand All @@ -211,8 +218,7 @@ function buildTarget({ moduleFormat, buildType, bundleState, input = 'src/index.
],
output: {
banner: isUMD ? getBanner(BANNER[buildType]) : undefined,
plugins: getOutPlugins(),
file: `${dir}/${OUT_PREFIX[buildType]}${isUMD ? '.js' : '.mjs'}`
file: `${dir}/${file}`
},
context: isUMD ? 'this' : undefined
};
Expand All @@ -230,15 +236,15 @@ function buildTarget({ moduleFormat, buildType, bundleState, input = 'src/index.
input,
output: {
banner: bundled ? getBanner(BANNER[buildType]) : undefined,
plugins: isMin ? getOutPlugins() : undefined,
plugins: buildType === 'release' ? getOutPlugins(isUMD ? 'umd' : 'es') : undefined,
format: isUMD ? 'umd' : 'es',
indent: '\t',
sourcemap: bundled && isDebug && 'inline',
name: 'pc',
preserveModules: !bundled,
preserveModulesRoot: !bundled ? rootDir : undefined,
file: bundled ? `${dir}/${OUT_PREFIX[buildType]}${isUMD ? '.js' : '.mjs'}` : undefined,
dir: !bundled ? `${dir}/${OUT_PREFIX[buildType]}` : undefined,
file: bundled ? `${dir}/${file}` : undefined,
dir: !bundled ? `${dir}/${prefix}` : undefined,
entryFileNames: chunkInfo => `${chunkInfo.name.replace(/node_modules/g, 'modules')}.js`
},
plugins: [
Expand Down