@vitus-labs/tools-rolldown 1.5.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/global/index.d.ts +20 -0
- package/lib/bin/run-build.js +4 -0
- package/lib/bin/run-build.js.map +1 -0
- package/lib/bin/run-watch.js +43 -0
- package/lib/bin/run-watch.js.map +1 -0
- package/lib/config/baseConfig.js +35 -0
- package/lib/config/baseConfig.js.map +1 -0
- package/lib/config/index.js +7 -0
- package/lib/config/index.js.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/lib/rolldown/config.js +90 -0
- package/lib/rolldown/config.js.map +1 -0
- package/lib/rolldown/createBuildPipeline.js +140 -0
- package/lib/rolldown/createBuildPipeline.js.map +1 -0
- package/lib/rolldown/index.js +4 -0
- package/lib/rolldown/index.js.map +1 -0
- package/lib/scripts/build.js +52 -0
- package/lib/scripts/build.js.map +1 -0
- package/lib/types/bin/run-build.d.ts +3 -0
- package/lib/types/bin/run-build.d.ts.map +1 -0
- package/lib/types/bin/run-watch.d.ts +3 -0
- package/lib/types/bin/run-watch.d.ts.map +1 -0
- package/lib/types/config/baseConfig.d.ts +25 -0
- package/lib/types/config/baseConfig.d.ts.map +1 -0
- package/lib/types/config/index.d.ts +5 -0
- package/lib/types/config/index.d.ts.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/rolldown/config.d.ts +26 -0
- package/lib/types/rolldown/config.d.ts.map +1 -0
- package/lib/types/rolldown/createBuildPipeline.d.ts +3 -0
- package/lib/types/rolldown/createBuildPipeline.d.ts.map +1 -0
- package/lib/types/rolldown/index.d.ts +4 -0
- package/lib/types/rolldown/index.d.ts.map +1 -0
- package/lib/types/scripts/build.d.ts +3 -0
- package/lib/types/scripts/build.d.ts.map +1 -0
- package/package.json +47 -0
- package/src/bin/run-build.ts +4 -0
- package/src/bin/run-watch.ts +54 -0
- package/src/config/baseConfig.ts +34 -0
- package/src/config/index.ts +10 -0
- package/src/index.ts +3 -0
- package/src/rolldown/config.ts +126 -0
- package/src/rolldown/createBuildPipeline.ts +171 -0
- package/src/rolldown/index.ts +4 -0
- package/src/scripts/build.ts +81 -0
- package/tsconfig.json +15 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [1.5.2-alpha.1](https://github.com/vitus-labs/tools/compare/v1.5.2-alpha.0...v1.5.2-alpha.1) (2026-02-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @vitus-labs/tools-rolldown
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.5.2-alpha.0](https://github.com/vitus-labs/tools/compare/v1.5.1...v1.5.2-alpha.0) (2026-02-06)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @vitus-labs/tools-rolldown
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vitus Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export {}
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
const __BROWSER__: true
|
|
6
|
+
const __WEB__: true
|
|
7
|
+
const __NATIVE__: true
|
|
8
|
+
const __NODE__: true
|
|
9
|
+
const __CLIENT__: true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
__BROWSER__: true
|
|
15
|
+
__WEB__: true
|
|
16
|
+
__NATIVE__: true
|
|
17
|
+
__NODE__: true
|
|
18
|
+
__CLIENT__: true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-build.js","sourceRoot":"","sources":["../../src/bin/run-build.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { watch } from 'rolldown';
|
|
4
|
+
import { PKG } from '../config/index.js';
|
|
5
|
+
import { createBuildPipeline, config as rolldownConfig, } from '../rolldown/index.js';
|
|
6
|
+
const { log } = console;
|
|
7
|
+
const allBuilds = createBuildPipeline();
|
|
8
|
+
const label = (text) => chalk.bold.bgCyan.black(` ${text} `);
|
|
9
|
+
const dim = chalk.dim;
|
|
10
|
+
const bold = chalk.bold;
|
|
11
|
+
const watchConfigs = allBuilds.map((item) => {
|
|
12
|
+
const { output, ...input } = rolldownConfig(item);
|
|
13
|
+
return { ...input, output };
|
|
14
|
+
});
|
|
15
|
+
log(`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim('watch mode')}\n`);
|
|
16
|
+
log(dim('Waiting for changes...\n'));
|
|
17
|
+
const watcher = watch(watchConfigs);
|
|
18
|
+
watcher.on('event', (event) => {
|
|
19
|
+
switch (event.code) {
|
|
20
|
+
case 'START':
|
|
21
|
+
log(dim('Rebuilding...'));
|
|
22
|
+
break;
|
|
23
|
+
case 'BUNDLE_END':
|
|
24
|
+
log(` ${chalk.green('+')} ${dim(event.output.join(', '))} ${dim(`(${event.duration}ms)`)}`);
|
|
25
|
+
event.result.close();
|
|
26
|
+
break;
|
|
27
|
+
case 'END':
|
|
28
|
+
log(`${chalk.green('Ready')} ${dim('- waiting for changes...')}\n`);
|
|
29
|
+
break;
|
|
30
|
+
case 'ERROR':
|
|
31
|
+
log(`\n${chalk.red('Error')} ${event.error.message || event.error}\n`);
|
|
32
|
+
if ('frame' in event.error && event.error.frame) {
|
|
33
|
+
log(dim(String(event.error.frame)));
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
process.on('SIGINT', () => {
|
|
39
|
+
log(dim('\nStopping...\n'));
|
|
40
|
+
watcher.close();
|
|
41
|
+
process.exit(0);
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=run-watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-watch.js","sourceRoot":"","sources":["../../src/bin/run-watch.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE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K,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,EAAE,CACxF,CAAA;YACD,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;YACpB,MAAK;QACP,KAAK,KAAK;YACR,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAA;YACnE,MAAK;QACP,KAAK,OAAO;YACV,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,CAAA;YACtE,IAAI,OAAO,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBAChD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACrC,CAAC;YACD,MAAK;IACT,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAC3B,OAAO,CAAC,KAAK,EAAE,CAAA;IACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
sourceDir: 'src',
|
|
3
|
+
outputDir: 'lib',
|
|
4
|
+
typesDir: 'lib/types',
|
|
5
|
+
typescript: true,
|
|
6
|
+
esModulesOnly: false,
|
|
7
|
+
replaceGlobals: true,
|
|
8
|
+
visualise: {
|
|
9
|
+
template: 'network',
|
|
10
|
+
gzipSize: true,
|
|
11
|
+
outputDir: 'analysis',
|
|
12
|
+
},
|
|
13
|
+
filesize: true,
|
|
14
|
+
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
|
|
15
|
+
include: ['src'],
|
|
16
|
+
external: ['react/jsx-runtime'],
|
|
17
|
+
exclude: [
|
|
18
|
+
'lib',
|
|
19
|
+
'node_modules/**',
|
|
20
|
+
'**/__tests__/**',
|
|
21
|
+
'**/__specs__/**',
|
|
22
|
+
'**/__stories__/**',
|
|
23
|
+
'*.test.*',
|
|
24
|
+
'*.spec.*',
|
|
25
|
+
'*.stories.*',
|
|
26
|
+
'stories.*',
|
|
27
|
+
'*.story.*',
|
|
28
|
+
],
|
|
29
|
+
globals: {
|
|
30
|
+
react: 'React',
|
|
31
|
+
ReactDOM: 'react-dom',
|
|
32
|
+
styled: 'styled-components',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=baseConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseConfig.js","sourceRoot":"","sources":["../../src/config/baseConfig.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,WAAW;IACrB,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,KAAK;IACpB,cAAc,EAAE,IAAI;IACpB,SAAS,EAAE;QACT,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,UAAU;KACtB;IACD,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC1E,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,QAAQ,EAAE,CAAC,mBAAmB,CAAC;IAC/B,OAAO,EAAE;QACP,KAAK;QACL,iBAAiB;QACjB,iBAAiB;QACjB,iBAAiB;QACjB,mBAAmB;QACnB,UAAU;QACV,UAAU;QACV,aAAa;QACb,WAAW;QACX,WAAW;KACZ;IACD,OAAO,EAAE;QACP,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE,WAAW;QACrB,MAAM,EAAE,mBAAmB;KAC5B;CACF,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PKG, TS_CONFIG, VL_CONFIG } from '@vitus-labs/tools-core';
|
|
2
|
+
import baseConfig from './baseConfig.js';
|
|
3
|
+
const CONFIG_KEY = 'build';
|
|
4
|
+
const CONFIG = VL_CONFIG(CONFIG_KEY).merge(baseConfig).config;
|
|
5
|
+
const PLATFORMS = ['browser', 'node', 'web', 'native'];
|
|
6
|
+
export { CONFIG, TS_CONFIG, PKG, PLATFORMS };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAExC,MAAM,UAAU,GAAG,OAAO,CAAA;AAE1B,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM,CAAA;AAE7D,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAA;AAE/D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAA"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { swapGlobals } from '@vitus-labs/tools-core';
|
|
2
|
+
import { dts } from 'rolldown-plugin-dts';
|
|
3
|
+
import filesize from 'rollup-plugin-filesize';
|
|
4
|
+
import { visualizer } from 'rollup-plugin-visualizer';
|
|
5
|
+
import { CONFIG, PKG, PLATFORMS } from '../config/index.js';
|
|
6
|
+
const defineExtensions = (platform) => {
|
|
7
|
+
const platformExtensions = [];
|
|
8
|
+
if (PLATFORMS.includes(platform)) {
|
|
9
|
+
CONFIG.extensions.forEach((item) => {
|
|
10
|
+
platformExtensions.push(`.${platform}${item}`);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return platformExtensions.concat(CONFIG.extensions);
|
|
14
|
+
};
|
|
15
|
+
const mapPlatform = (platform) => {
|
|
16
|
+
if (platform === 'node')
|
|
17
|
+
return 'node';
|
|
18
|
+
if (platform === 'browser')
|
|
19
|
+
return 'browser';
|
|
20
|
+
return 'neutral';
|
|
21
|
+
};
|
|
22
|
+
const loadPlugins = ({ file, typesFilePath, }) => {
|
|
23
|
+
const plugins = [];
|
|
24
|
+
if (CONFIG.typescript && typesFilePath) {
|
|
25
|
+
plugins.push(...dts({
|
|
26
|
+
tsconfig: 'tsconfig.json',
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
// generate visualised graphs in dist folder
|
|
30
|
+
if (CONFIG.visualise) {
|
|
31
|
+
const filePath = file.split('/');
|
|
32
|
+
const fileName = filePath.pop();
|
|
33
|
+
const visualiserOptions = {
|
|
34
|
+
title: `${PKG.name} - ${fileName}`,
|
|
35
|
+
filename: `${filePath.join('/')}/${CONFIG.visualise.outputDir}/${fileName}.html`,
|
|
36
|
+
template: CONFIG.visualise.template,
|
|
37
|
+
gzipSize: CONFIG.visualise.gzipSize,
|
|
38
|
+
};
|
|
39
|
+
plugins.push(visualizer(visualiserOptions));
|
|
40
|
+
}
|
|
41
|
+
if (CONFIG.filesize) {
|
|
42
|
+
plugins.push(filesize());
|
|
43
|
+
}
|
|
44
|
+
return plugins;
|
|
45
|
+
};
|
|
46
|
+
const buildDefineOptions = (env, platform) => {
|
|
47
|
+
if (!CONFIG.replaceGlobals)
|
|
48
|
+
return undefined;
|
|
49
|
+
const defineOptions = {
|
|
50
|
+
__VERSION__: JSON.stringify(PKG.version),
|
|
51
|
+
__NODE__: JSON.stringify(platform === 'node'),
|
|
52
|
+
__WEB__: JSON.stringify(['node', 'browser', 'universal'].includes(platform)),
|
|
53
|
+
__BROWSER__: JSON.stringify(platform === 'browser'),
|
|
54
|
+
__NATIVE__: JSON.stringify(platform === 'native'),
|
|
55
|
+
__CLIENT__: JSON.stringify(['native', 'browser'].includes(platform)),
|
|
56
|
+
};
|
|
57
|
+
if (env === 'production') {
|
|
58
|
+
defineOptions['process.env.NODE_ENV'] = JSON.stringify(env);
|
|
59
|
+
}
|
|
60
|
+
return defineOptions;
|
|
61
|
+
};
|
|
62
|
+
const rolldownConfig = ({ file, format, env, typesFilePath, platform, }) => {
|
|
63
|
+
const extensions = defineExtensions(platform);
|
|
64
|
+
const plugins = loadPlugins({ file, typesFilePath });
|
|
65
|
+
const define = buildDefineOptions(env, platform);
|
|
66
|
+
const buildOutput = {
|
|
67
|
+
input: CONFIG.sourceDir,
|
|
68
|
+
platform: mapPlatform(platform),
|
|
69
|
+
tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,
|
|
70
|
+
resolve: {
|
|
71
|
+
extensions,
|
|
72
|
+
},
|
|
73
|
+
transform: define ? { define } : undefined,
|
|
74
|
+
output: {
|
|
75
|
+
file,
|
|
76
|
+
format,
|
|
77
|
+
globals: swapGlobals(CONFIG.globals),
|
|
78
|
+
sourcemap: true,
|
|
79
|
+
exports: ['cjs', 'umd'].includes(format) ? 'named' : undefined,
|
|
80
|
+
name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,
|
|
81
|
+
esModule: true,
|
|
82
|
+
minify: env === 'production',
|
|
83
|
+
},
|
|
84
|
+
external: [...PKG.externalDependencies, ...CONFIG.external],
|
|
85
|
+
plugins,
|
|
86
|
+
};
|
|
87
|
+
return buildOutput;
|
|
88
|
+
};
|
|
89
|
+
export default rolldownConfig;
|
|
90
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/rolldown/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,QAAQ,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE3D,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC5C,MAAM,kBAAkB,GAAa,EAAE,CAAA;IAEvC,IAAK,SAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAY,EAAE,EAAE;YACzC,kBAAkB,CAAC,IAAI,CAAC,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,QAAgB,EAC4B,EAAE;IAC9C,IAAI,QAAQ,KAAK,MAAM;QAAE,OAAO,MAAM,CAAA;IACtC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC5C,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,EACnB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I;YACJ,MAAM;YACN,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;YACpC,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,OAAiB,CAAC,CAAC,CAAC,SAAS;YACzE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;YACnE,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,GAAG,KAAK,YAAY;SAC7B;QACD,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,oBAAoB,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC3D,OAAO;KACR,CAAA;IAED,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { PKG } from '../config/index.js';
|
|
2
|
+
const isESModuleOnly = PKG.type === 'module';
|
|
3
|
+
const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings;
|
|
4
|
+
const hasDifferentNativeBuild = () => {
|
|
5
|
+
return PKG['react-native'] !== PKG.module;
|
|
6
|
+
};
|
|
7
|
+
const hasDifferentBrowserBuild = (type) => {
|
|
8
|
+
if (!PKG.browser)
|
|
9
|
+
return false;
|
|
10
|
+
return Object.entries(PKG.browser).some(([key, value]) => {
|
|
11
|
+
const source = key.substring(2);
|
|
12
|
+
const output = value.substring(2);
|
|
13
|
+
return source !== PKG[type] && source !== output;
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const BUILD_VARIANTS = {
|
|
17
|
+
main: {
|
|
18
|
+
format: isESModuleOnly ? 'es' : 'cjs',
|
|
19
|
+
env: 'development',
|
|
20
|
+
platform: 'universal',
|
|
21
|
+
},
|
|
22
|
+
module: {
|
|
23
|
+
format: 'es',
|
|
24
|
+
env: 'development',
|
|
25
|
+
platform: 'universal',
|
|
26
|
+
},
|
|
27
|
+
'react-native': {
|
|
28
|
+
format: 'es',
|
|
29
|
+
env: 'development',
|
|
30
|
+
platform: 'native',
|
|
31
|
+
},
|
|
32
|
+
'umd:main': { format: 'umd', env: 'development' },
|
|
33
|
+
unpkg: { format: 'umd', env: 'production' },
|
|
34
|
+
};
|
|
35
|
+
const getExportsOptions = () => {
|
|
36
|
+
const exportsOptions = PKG.exports;
|
|
37
|
+
if (!exportsOptions)
|
|
38
|
+
return [];
|
|
39
|
+
if (typeof exportsOptions === 'string') {
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
file: PKG.exports,
|
|
43
|
+
...BUILD_VARIANTS.module,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
if (typeof exportsOptions === 'object') {
|
|
48
|
+
const result = [];
|
|
49
|
+
if (exportsOptions.import) {
|
|
50
|
+
result.push({
|
|
51
|
+
file: exportsOptions.import,
|
|
52
|
+
...BUILD_VARIANTS.module,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (exportsOptions.require) {
|
|
56
|
+
result.push({
|
|
57
|
+
file: exportsOptions.require,
|
|
58
|
+
...BUILD_VARIANTS.main,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (exportsOptions.node) {
|
|
62
|
+
result.push({
|
|
63
|
+
file: exportsOptions.node,
|
|
64
|
+
...BUILD_VARIANTS.module,
|
|
65
|
+
platform: 'node',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (exportsOptions.default) {
|
|
69
|
+
result.push({
|
|
70
|
+
file: exportsOptions.default,
|
|
71
|
+
...BUILD_VARIANTS.module,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
};
|
|
78
|
+
const createBasicBuildVariants = () => {
|
|
79
|
+
let result = [];
|
|
80
|
+
if (isESModuleOnly)
|
|
81
|
+
result = [...getExportsOptions()];
|
|
82
|
+
Object.keys(BUILD_VARIANTS).forEach((key) => {
|
|
83
|
+
const PKGOutDir = PKG[key];
|
|
84
|
+
if (PKGOutDir) {
|
|
85
|
+
const hasBrowserBuild = hasDifferentBrowserBuild(key);
|
|
86
|
+
const hasNativeBuild = hasDifferentNativeBuild();
|
|
87
|
+
// create a helper function for adding a build variant to an array
|
|
88
|
+
const add = (props = {}) => {
|
|
89
|
+
result.push({ ...BUILD_VARIANTS[key], file: PKGOutDir, ...props });
|
|
90
|
+
};
|
|
91
|
+
if (key === 'react-native') {
|
|
92
|
+
// add a separate RN build only if output path differs from module path
|
|
93
|
+
if (hasNativeBuild) {
|
|
94
|
+
add();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (hasBrowserBuild) {
|
|
98
|
+
// if has a different browser build, set default platform to node
|
|
99
|
+
// as there is going to be created a separate browser build as well
|
|
100
|
+
add({ platform: 'node' });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
add();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
const createBrowserBuildVariants = () => {
|
|
110
|
+
const result = [];
|
|
111
|
+
if (!PKG.browser)
|
|
112
|
+
return result;
|
|
113
|
+
Object.entries(PKG.browser).forEach(([key, value]) => {
|
|
114
|
+
const source = key.substring(2); // strip './' from the beginning of path
|
|
115
|
+
const output = value.substring(2); // strip './' from the beginning of path
|
|
116
|
+
Object.keys(BUILD_VARIANTS).forEach((item) => {
|
|
117
|
+
if (PKG[item] === source && source !== output) {
|
|
118
|
+
result.push({
|
|
119
|
+
...BUILD_VARIANTS[item],
|
|
120
|
+
file: output,
|
|
121
|
+
platform: 'browser',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
const createBuildPipeline = () => {
|
|
129
|
+
const result = [
|
|
130
|
+
...createBasicBuildVariants(),
|
|
131
|
+
...createBrowserBuildVariants(),
|
|
132
|
+
];
|
|
133
|
+
// add generate typings for the first bundle only
|
|
134
|
+
if (typesFilePath) {
|
|
135
|
+
result[0] = { ...result[0], typesFilePath };
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
};
|
|
139
|
+
export default createBuildPipeline;
|
|
140
|
+
//# sourceMappingURL=createBuildPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBuildPipeline.js","sourceRoot":"","sources":["../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAExC,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAC5C,MAAM,aAAa,GAAG,GAAG,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAA;AAErE,MAAM,uBAAuB,GAAG,GAAG,EAAE;IACnC,OAAO,GAAG,CAAC,cAAc,CAAC,KAAK,GAAG,CAAC,MAAM,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IAChD,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAE9B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAiC,CAAC,CAAC,IAAI,CAC/D,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACf,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAEjC,OAAO,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,KAAK,MAAM,C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BAA0B,EAAE;KAChC,CAAA;IAED,iDAAiD;IACjD,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAA;IAC7C,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rolldown/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,mBAAmB,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { rimraf } from 'rimraf';
|
|
3
|
+
import { rolldown } from 'rolldown';
|
|
4
|
+
import { CONFIG, PKG } from '../config/index.js';
|
|
5
|
+
import { createBuildPipeline, config as rolldownConfig, } from '../rolldown/index.js';
|
|
6
|
+
const { log } = console;
|
|
7
|
+
const allBuilds = createBuildPipeline();
|
|
8
|
+
const allBuildsCount = allBuilds.length;
|
|
9
|
+
const FORMAT_LABEL = {
|
|
10
|
+
cjs: 'CJS',
|
|
11
|
+
es: 'ESM',
|
|
12
|
+
umd: 'UMD',
|
|
13
|
+
};
|
|
14
|
+
const label = (text) => chalk.bold.bgCyan.black(` ${text} `);
|
|
15
|
+
const dim = chalk.dim;
|
|
16
|
+
const bold = chalk.bold;
|
|
17
|
+
async function build({ inputOptions, outputOptions, }) {
|
|
18
|
+
const bundle = await rolldown(inputOptions);
|
|
19
|
+
await bundle.write(outputOptions);
|
|
20
|
+
await bundle.close();
|
|
21
|
+
}
|
|
22
|
+
const createBuilds = async () => {
|
|
23
|
+
let p = Promise.resolve();
|
|
24
|
+
allBuilds.forEach((item) => {
|
|
25
|
+
const { output, ...input } = rolldownConfig(item);
|
|
26
|
+
const format = FORMAT_LABEL[output.format] || output.format;
|
|
27
|
+
p = p.then(() => {
|
|
28
|
+
const start = performance.now();
|
|
29
|
+
return build({ inputOptions: input, outputOptions: output }).then(() => {
|
|
30
|
+
const duration = Math.round(performance.now() - start);
|
|
31
|
+
log(` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(output.file)} ${dim(`(${duration}ms)`)}`);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return p.catch((e) => {
|
|
36
|
+
log(`\n${chalk.bold.red('Build failed')}\n`);
|
|
37
|
+
log(e);
|
|
38
|
+
throw e;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const runBuild = async () => {
|
|
42
|
+
const start = performance.now();
|
|
43
|
+
log(`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\n`);
|
|
44
|
+
log(`${dim('Cleaning')} ${CONFIG.outputDir}/`);
|
|
45
|
+
rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`);
|
|
46
|
+
log(`${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\n`);
|
|
47
|
+
await createBuilds();
|
|
48
|
+
const total = Math.round(performance.now() - start);
|
|
49
|
+
log(`\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\n`);
|
|
50
|
+
};
|
|
51
|
+
export { runBuild };
|
|
52
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/scripts/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAChD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ACD,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,UAAU,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CACjG,CAAA;IAED,MAAM,YAAY,EAAE,CAAA;IAEpB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAA;IACnD,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,CAAA;AAC3D,CAAC,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-build.d.ts","sourceRoot":"","sources":["../../../src/bin/run-build.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-watch.d.ts","sourceRoot":"","sources":["../../../src/bin/run-watch.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
sourceDir: string;
|
|
3
|
+
outputDir: string;
|
|
4
|
+
typesDir: string;
|
|
5
|
+
typescript: boolean;
|
|
6
|
+
esModulesOnly: boolean;
|
|
7
|
+
replaceGlobals: boolean;
|
|
8
|
+
visualise: {
|
|
9
|
+
template: string;
|
|
10
|
+
gzipSize: boolean;
|
|
11
|
+
outputDir: string;
|
|
12
|
+
};
|
|
13
|
+
filesize: boolean;
|
|
14
|
+
extensions: string[];
|
|
15
|
+
include: string[];
|
|
16
|
+
external: string[];
|
|
17
|
+
exclude: string[];
|
|
18
|
+
globals: {
|
|
19
|
+
react: string;
|
|
20
|
+
ReactDOM: string;
|
|
21
|
+
styled: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
|
25
|
+
//# sourceMappingURL=baseConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseConfig.d.ts","sourceRoot":"","sources":["../../../src/config/baseConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAiCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAa,MAAM,wBAAwB,CAAA;AAKlE,QAAA,MAAM,MAAM,KAAiD,CAAA;AAE7D,QAAA,MAAM,SAAS,+CAAgD,CAAA;AAE/D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RolldownPlugin } from 'rolldown';
|
|
2
|
+
declare const rolldownConfig: ({ file, format, env, typesFilePath, platform, }: Record<string, any>) => {
|
|
3
|
+
input: any;
|
|
4
|
+
platform: "browser" | "node" | "neutral" | undefined;
|
|
5
|
+
tsconfig: string | undefined;
|
|
6
|
+
resolve: {
|
|
7
|
+
extensions: string[];
|
|
8
|
+
};
|
|
9
|
+
transform: {
|
|
10
|
+
define: Record<string, string>;
|
|
11
|
+
} | undefined;
|
|
12
|
+
output: {
|
|
13
|
+
file: any;
|
|
14
|
+
format: any;
|
|
15
|
+
globals: Record<string, string>;
|
|
16
|
+
sourcemap: boolean;
|
|
17
|
+
exports: "named" | undefined;
|
|
18
|
+
name: any;
|
|
19
|
+
esModule: boolean;
|
|
20
|
+
minify: boolean;
|
|
21
|
+
};
|
|
22
|
+
external: any[];
|
|
23
|
+
plugins: RolldownPlugin[];
|
|
24
|
+
};
|
|
25
|
+
export default rolldownConfig;
|
|
26
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/rolldown/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAwF9C,QAAA,MAAM,cAAc,GAAI,iDAMrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;CA4BrB,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBuildPipeline.d.ts","sourceRoot":"","sources":["../../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AA4JA,QAAA,MAAM,mBAAmB,6BAYxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rolldown/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,mBAAmB,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AA4DA,QAAA,MAAM,QAAQ,qBAkBb,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitus-labs/tools-rolldown",
|
|
3
|
+
"version": "1.5.2-alpha.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Vit Bokisch <vit@bokisch.com>",
|
|
6
|
+
"maintainers": [
|
|
7
|
+
"Vit Bokisch <vit@bokisch.com>"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./lib/types/index.d.ts",
|
|
13
|
+
"import": "./lib/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./global": {
|
|
16
|
+
"types": "./global/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"vl_rolldown_build": "./lib/bin/run-build.js",
|
|
21
|
+
"vl_rolldown_build-watch": "./lib/bin/run-watch.js"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">= 22"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prepublish": "bun run build",
|
|
28
|
+
"build": "tsc"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@vitus-labs/tools-core": "1.5.2-alpha.0",
|
|
35
|
+
"chalk": "^5.6.2",
|
|
36
|
+
"rimraf": "^6.1.2",
|
|
37
|
+
"rolldown": "^1.0.0-rc.3",
|
|
38
|
+
"rolldown-plugin-dts": "^0.13.4",
|
|
39
|
+
"rollup-plugin-filesize": "^10.0.0",
|
|
40
|
+
"rollup-plugin-visualizer": "^5.14.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@vitus-labs/tools-typescript": "1.5.2-alpha.0",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "5b0b8c0a427559dff76158176367fd9b3588dc60"
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import { watch } from 'rolldown'
|
|
4
|
+
import { PKG } from '../config/index.js'
|
|
5
|
+
import {
|
|
6
|
+
createBuildPipeline,
|
|
7
|
+
config as rolldownConfig,
|
|
8
|
+
} from '../rolldown/index.js'
|
|
9
|
+
|
|
10
|
+
const { log } = console
|
|
11
|
+
const allBuilds = createBuildPipeline()
|
|
12
|
+
|
|
13
|
+
const label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)
|
|
14
|
+
const dim = chalk.dim
|
|
15
|
+
const bold = chalk.bold
|
|
16
|
+
|
|
17
|
+
const watchConfigs = allBuilds.map((item) => {
|
|
18
|
+
const { output, ...input } = rolldownConfig(item)
|
|
19
|
+
return { ...input, output }
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
log(`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim('watch mode')}\n`)
|
|
23
|
+
log(dim('Waiting for changes...\n'))
|
|
24
|
+
|
|
25
|
+
const watcher = watch(watchConfigs)
|
|
26
|
+
|
|
27
|
+
watcher.on('event', (event) => {
|
|
28
|
+
switch (event.code) {
|
|
29
|
+
case 'START':
|
|
30
|
+
log(dim('Rebuilding...'))
|
|
31
|
+
break
|
|
32
|
+
case 'BUNDLE_END':
|
|
33
|
+
log(
|
|
34
|
+
` ${chalk.green('+')} ${dim(event.output.join(', '))} ${dim(`(${event.duration}ms)`)}`,
|
|
35
|
+
)
|
|
36
|
+
event.result.close()
|
|
37
|
+
break
|
|
38
|
+
case 'END':
|
|
39
|
+
log(`${chalk.green('Ready')} ${dim('- waiting for changes...')}\n`)
|
|
40
|
+
break
|
|
41
|
+
case 'ERROR':
|
|
42
|
+
log(`\n${chalk.red('Error')} ${event.error.message || event.error}\n`)
|
|
43
|
+
if ('frame' in event.error && event.error.frame) {
|
|
44
|
+
log(dim(String(event.error.frame)))
|
|
45
|
+
}
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
process.on('SIGINT', () => {
|
|
51
|
+
log(dim('\nStopping...\n'))
|
|
52
|
+
watcher.close()
|
|
53
|
+
process.exit(0)
|
|
54
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
sourceDir: 'src',
|
|
3
|
+
outputDir: 'lib',
|
|
4
|
+
typesDir: 'lib/types',
|
|
5
|
+
typescript: true,
|
|
6
|
+
esModulesOnly: false,
|
|
7
|
+
replaceGlobals: true,
|
|
8
|
+
visualise: {
|
|
9
|
+
template: 'network',
|
|
10
|
+
gzipSize: true,
|
|
11
|
+
outputDir: 'analysis',
|
|
12
|
+
},
|
|
13
|
+
filesize: true,
|
|
14
|
+
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
|
|
15
|
+
include: ['src'],
|
|
16
|
+
external: ['react/jsx-runtime'],
|
|
17
|
+
exclude: [
|
|
18
|
+
'lib',
|
|
19
|
+
'node_modules/**',
|
|
20
|
+
'**/__tests__/**',
|
|
21
|
+
'**/__specs__/**',
|
|
22
|
+
'**/__stories__/**',
|
|
23
|
+
'*.test.*',
|
|
24
|
+
'*.spec.*',
|
|
25
|
+
'*.stories.*',
|
|
26
|
+
'stories.*',
|
|
27
|
+
'*.story.*',
|
|
28
|
+
],
|
|
29
|
+
globals: {
|
|
30
|
+
react: 'React',
|
|
31
|
+
ReactDOM: 'react-dom',
|
|
32
|
+
styled: 'styled-components',
|
|
33
|
+
},
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PKG, TS_CONFIG, VL_CONFIG } from '@vitus-labs/tools-core'
|
|
2
|
+
import baseConfig from './baseConfig.js'
|
|
3
|
+
|
|
4
|
+
const CONFIG_KEY = 'build'
|
|
5
|
+
|
|
6
|
+
const CONFIG = VL_CONFIG(CONFIG_KEY).merge(baseConfig).config
|
|
7
|
+
|
|
8
|
+
const PLATFORMS = ['browser', 'node', 'web', 'native'] as const
|
|
9
|
+
|
|
10
|
+
export { CONFIG, TS_CONFIG, PKG, PLATFORMS }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { swapGlobals } from '@vitus-labs/tools-core'
|
|
2
|
+
import type { RolldownPlugin } from 'rolldown'
|
|
3
|
+
import { dts } from 'rolldown-plugin-dts'
|
|
4
|
+
import filesize from 'rollup-plugin-filesize'
|
|
5
|
+
import { visualizer } from 'rollup-plugin-visualizer'
|
|
6
|
+
import { CONFIG, PKG, PLATFORMS } from '../config/index.js'
|
|
7
|
+
|
|
8
|
+
const defineExtensions = (platform: string) => {
|
|
9
|
+
const platformExtensions: string[] = []
|
|
10
|
+
|
|
11
|
+
if ((PLATFORMS as readonly string[]).includes(platform)) {
|
|
12
|
+
CONFIG.extensions.forEach((item: string) => {
|
|
13
|
+
platformExtensions.push(`.${platform}${item}`)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return platformExtensions.concat(CONFIG.extensions)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const mapPlatform = (
|
|
21
|
+
platform: string,
|
|
22
|
+
): 'node' | 'browser' | 'neutral' | undefined => {
|
|
23
|
+
if (platform === 'node') return 'node'
|
|
24
|
+
if (platform === 'browser') return 'browser'
|
|
25
|
+
return 'neutral'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const loadPlugins = ({
|
|
29
|
+
file,
|
|
30
|
+
typesFilePath,
|
|
31
|
+
}: {
|
|
32
|
+
file: string
|
|
33
|
+
typesFilePath?: string
|
|
34
|
+
}) => {
|
|
35
|
+
const plugins: RolldownPlugin[] = []
|
|
36
|
+
|
|
37
|
+
if (CONFIG.typescript && typesFilePath) {
|
|
38
|
+
plugins.push(
|
|
39
|
+
...(dts({
|
|
40
|
+
tsconfig: 'tsconfig.json',
|
|
41
|
+
}) as RolldownPlugin[]),
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// generate visualised graphs in dist folder
|
|
46
|
+
if (CONFIG.visualise) {
|
|
47
|
+
const filePath = file.split('/')
|
|
48
|
+
const fileName = filePath.pop()
|
|
49
|
+
|
|
50
|
+
const visualiserOptions = {
|
|
51
|
+
title: `${PKG.name} - ${fileName}`,
|
|
52
|
+
filename: `${filePath.join('/')}/${
|
|
53
|
+
CONFIG.visualise.outputDir
|
|
54
|
+
}/${fileName}.html`,
|
|
55
|
+
template: CONFIG.visualise.template,
|
|
56
|
+
gzipSize: CONFIG.visualise.gzipSize,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
plugins.push(visualizer(visualiserOptions) as RolldownPlugin)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (CONFIG.filesize) {
|
|
63
|
+
plugins.push(filesize() as RolldownPlugin)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return plugins
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const buildDefineOptions = (env: string, platform: string) => {
|
|
70
|
+
if (!CONFIG.replaceGlobals) return undefined
|
|
71
|
+
|
|
72
|
+
const defineOptions: Record<string, string> = {
|
|
73
|
+
__VERSION__: JSON.stringify(PKG.version),
|
|
74
|
+
__NODE__: JSON.stringify(platform === 'node'),
|
|
75
|
+
__WEB__: JSON.stringify(
|
|
76
|
+
['node', 'browser', 'universal'].includes(platform),
|
|
77
|
+
),
|
|
78
|
+
__BROWSER__: JSON.stringify(platform === 'browser'),
|
|
79
|
+
__NATIVE__: JSON.stringify(platform === 'native'),
|
|
80
|
+
__CLIENT__: JSON.stringify(['native', 'browser'].includes(platform)),
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (env === 'production') {
|
|
84
|
+
defineOptions['process.env.NODE_ENV'] = JSON.stringify(env)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return defineOptions
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const rolldownConfig = ({
|
|
91
|
+
file,
|
|
92
|
+
format,
|
|
93
|
+
env,
|
|
94
|
+
typesFilePath,
|
|
95
|
+
platform,
|
|
96
|
+
}: Record<string, any>) => {
|
|
97
|
+
const extensions = defineExtensions(platform)
|
|
98
|
+
const plugins = loadPlugins({ file, typesFilePath })
|
|
99
|
+
const define = buildDefineOptions(env, platform)
|
|
100
|
+
|
|
101
|
+
const buildOutput = {
|
|
102
|
+
input: CONFIG.sourceDir,
|
|
103
|
+
platform: mapPlatform(platform),
|
|
104
|
+
tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,
|
|
105
|
+
resolve: {
|
|
106
|
+
extensions,
|
|
107
|
+
},
|
|
108
|
+
transform: define ? { define } : undefined,
|
|
109
|
+
output: {
|
|
110
|
+
file,
|
|
111
|
+
format,
|
|
112
|
+
globals: swapGlobals(CONFIG.globals),
|
|
113
|
+
sourcemap: true,
|
|
114
|
+
exports: ['cjs', 'umd'].includes(format) ? ('named' as const) : undefined,
|
|
115
|
+
name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,
|
|
116
|
+
esModule: true,
|
|
117
|
+
minify: env === 'production',
|
|
118
|
+
},
|
|
119
|
+
external: [...PKG.externalDependencies, ...CONFIG.external],
|
|
120
|
+
plugins,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return buildOutput
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export default rolldownConfig
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { PKG } from '../config/index.js'
|
|
2
|
+
|
|
3
|
+
const isESModuleOnly = PKG.type === 'module'
|
|
4
|
+
const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings
|
|
5
|
+
|
|
6
|
+
const hasDifferentNativeBuild = () => {
|
|
7
|
+
return PKG['react-native'] !== PKG.module
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const hasDifferentBrowserBuild = (type: string) => {
|
|
11
|
+
if (!PKG.browser) return false
|
|
12
|
+
|
|
13
|
+
return Object.entries(PKG.browser as Record<string, string>).some(
|
|
14
|
+
([key, value]) => {
|
|
15
|
+
const source = key.substring(2)
|
|
16
|
+
const output = value.substring(2)
|
|
17
|
+
|
|
18
|
+
return source !== PKG[type] && source !== output
|
|
19
|
+
},
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const BUILD_VARIANTS: Record<
|
|
24
|
+
string,
|
|
25
|
+
{ format: string; env: string; platform?: string }
|
|
26
|
+
> = {
|
|
27
|
+
main: {
|
|
28
|
+
format: isESModuleOnly ? 'es' : 'cjs',
|
|
29
|
+
env: 'development',
|
|
30
|
+
platform: 'universal',
|
|
31
|
+
},
|
|
32
|
+
module: {
|
|
33
|
+
format: 'es',
|
|
34
|
+
env: 'development',
|
|
35
|
+
platform: 'universal',
|
|
36
|
+
},
|
|
37
|
+
'react-native': {
|
|
38
|
+
format: 'es',
|
|
39
|
+
env: 'development',
|
|
40
|
+
platform: 'native',
|
|
41
|
+
},
|
|
42
|
+
'umd:main': { format: 'umd', env: 'development' },
|
|
43
|
+
unpkg: { format: 'umd', env: 'production' },
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getExportsOptions = () => {
|
|
47
|
+
const exportsOptions = PKG.exports
|
|
48
|
+
|
|
49
|
+
if (!exportsOptions) return []
|
|
50
|
+
|
|
51
|
+
if (typeof exportsOptions === 'string') {
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
file: PKG.exports,
|
|
55
|
+
...BUILD_VARIANTS.module,
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof exportsOptions === 'object') {
|
|
61
|
+
const result: Record<string, any>[] = []
|
|
62
|
+
|
|
63
|
+
if (exportsOptions.import) {
|
|
64
|
+
result.push({
|
|
65
|
+
file: exportsOptions.import,
|
|
66
|
+
...BUILD_VARIANTS.module,
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (exportsOptions.require) {
|
|
71
|
+
result.push({
|
|
72
|
+
file: exportsOptions.require,
|
|
73
|
+
...BUILD_VARIANTS.main,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (exportsOptions.node) {
|
|
78
|
+
result.push({
|
|
79
|
+
file: exportsOptions.node,
|
|
80
|
+
...BUILD_VARIANTS.module,
|
|
81
|
+
platform: 'node',
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (exportsOptions.default) {
|
|
86
|
+
result.push({
|
|
87
|
+
file: exportsOptions.default,
|
|
88
|
+
...BUILD_VARIANTS.module,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return result
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return []
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const createBasicBuildVariants = () => {
|
|
99
|
+
let result: Record<string, any>[] = []
|
|
100
|
+
|
|
101
|
+
if (isESModuleOnly) result = [...getExportsOptions()]
|
|
102
|
+
|
|
103
|
+
Object.keys(BUILD_VARIANTS).forEach((key) => {
|
|
104
|
+
const PKGOutDir = PKG[key]
|
|
105
|
+
|
|
106
|
+
if (PKGOutDir) {
|
|
107
|
+
const hasBrowserBuild = hasDifferentBrowserBuild(key)
|
|
108
|
+
const hasNativeBuild = hasDifferentNativeBuild()
|
|
109
|
+
|
|
110
|
+
// create a helper function for adding a build variant to an array
|
|
111
|
+
const add = (props = {}) => {
|
|
112
|
+
result.push({ ...BUILD_VARIANTS[key], file: PKGOutDir, ...props })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (key === 'react-native') {
|
|
116
|
+
// add a separate RN build only if output path differs from module path
|
|
117
|
+
if (hasNativeBuild) {
|
|
118
|
+
add()
|
|
119
|
+
}
|
|
120
|
+
} else if (hasBrowserBuild) {
|
|
121
|
+
// if has a different browser build, set default platform to node
|
|
122
|
+
// as there is going to be created a separate browser build as well
|
|
123
|
+
add({ platform: 'node' })
|
|
124
|
+
} else {
|
|
125
|
+
add()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
return result
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const createBrowserBuildVariants = () => {
|
|
134
|
+
const result: Record<string, any>[] = []
|
|
135
|
+
if (!PKG.browser) return result
|
|
136
|
+
|
|
137
|
+
Object.entries(PKG.browser as Record<string, string>).forEach(
|
|
138
|
+
([key, value]) => {
|
|
139
|
+
const source = key.substring(2) // strip './' from the beginning of path
|
|
140
|
+
const output = value.substring(2) // strip './' from the beginning of path
|
|
141
|
+
|
|
142
|
+
Object.keys(BUILD_VARIANTS).forEach((item) => {
|
|
143
|
+
if (PKG[item] === source && source !== output) {
|
|
144
|
+
result.push({
|
|
145
|
+
...BUILD_VARIANTS[item],
|
|
146
|
+
file: output,
|
|
147
|
+
platform: 'browser',
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
},
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
return result
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const createBuildPipeline = () => {
|
|
158
|
+
const result = [
|
|
159
|
+
...createBasicBuildVariants(),
|
|
160
|
+
...createBrowserBuildVariants(),
|
|
161
|
+
]
|
|
162
|
+
|
|
163
|
+
// add generate typings for the first bundle only
|
|
164
|
+
if (typesFilePath) {
|
|
165
|
+
result[0] = { ...result[0], typesFilePath }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return result
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export default createBuildPipeline
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { rimraf } from 'rimraf'
|
|
3
|
+
import { rolldown } from 'rolldown'
|
|
4
|
+
import { CONFIG, PKG } from '../config/index.js'
|
|
5
|
+
import {
|
|
6
|
+
createBuildPipeline,
|
|
7
|
+
config as rolldownConfig,
|
|
8
|
+
} from '../rolldown/index.js'
|
|
9
|
+
|
|
10
|
+
const { log } = console
|
|
11
|
+
const allBuilds = createBuildPipeline()
|
|
12
|
+
const allBuildsCount = allBuilds.length
|
|
13
|
+
|
|
14
|
+
const FORMAT_LABEL: Record<string, string> = {
|
|
15
|
+
cjs: 'CJS',
|
|
16
|
+
es: 'ESM',
|
|
17
|
+
umd: 'UMD',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)
|
|
21
|
+
const dim = chalk.dim
|
|
22
|
+
const bold = chalk.bold
|
|
23
|
+
|
|
24
|
+
async function build({
|
|
25
|
+
inputOptions,
|
|
26
|
+
outputOptions,
|
|
27
|
+
}: {
|
|
28
|
+
inputOptions: any
|
|
29
|
+
outputOptions: any
|
|
30
|
+
}) {
|
|
31
|
+
const bundle = await rolldown(inputOptions)
|
|
32
|
+
await bundle.write(outputOptions)
|
|
33
|
+
await bundle.close()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const createBuilds = async () => {
|
|
37
|
+
let p = Promise.resolve()
|
|
38
|
+
|
|
39
|
+
allBuilds.forEach((item) => {
|
|
40
|
+
const { output, ...input } = rolldownConfig(item)
|
|
41
|
+
const format = FORMAT_LABEL[output.format] || output.format
|
|
42
|
+
p = p.then(() => {
|
|
43
|
+
const start = performance.now()
|
|
44
|
+
|
|
45
|
+
return build({ inputOptions: input, outputOptions: output }).then(() => {
|
|
46
|
+
const duration = Math.round(performance.now() - start)
|
|
47
|
+
log(
|
|
48
|
+
` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(output.file)} ${dim(`(${duration}ms)`)}`,
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return p.catch((e) => {
|
|
55
|
+
log(`\n${chalk.bold.red('Build failed')}\n`)
|
|
56
|
+
log(e)
|
|
57
|
+
throw e
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const runBuild = async () => {
|
|
62
|
+
const start = performance.now()
|
|
63
|
+
|
|
64
|
+
log(
|
|
65
|
+
`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\n`,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
log(`${dim('Cleaning')} ${CONFIG.outputDir}/`)
|
|
69
|
+
rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`)
|
|
70
|
+
|
|
71
|
+
log(
|
|
72
|
+
`${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\n`,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
await createBuilds()
|
|
76
|
+
|
|
77
|
+
const total = Math.round(performance.now() - start)
|
|
78
|
+
log(`\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\n`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { runBuild }
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@vitus-labs/tools-typescript/lib",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"noEmit": false,
|
|
5
|
+
"outDir": "lib",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"baseUrl": ".",
|
|
8
|
+
"declarationDir": "./lib/types",
|
|
9
|
+
"paths": {
|
|
10
|
+
"~/*": ["src/*"]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"include": ["typings", "src"],
|
|
14
|
+
"exclude": ["node_modules", "__stories__", "lib"]
|
|
15
|
+
}
|