@vitus-labs/tools-rolldown 1.11.1-alpha.1 → 1.12.1-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/README.md +52 -0
- package/lib/bin/run-watch.js.map +1 -1
- package/lib/config/baseConfig.js +8 -0
- package/lib/config/baseConfig.js.map +1 -1
- package/lib/rolldown/config.js +18 -7
- package/lib/rolldown/config.js.map +1 -1
- package/lib/rolldown/createBuildPipeline.js +10 -1
- package/lib/rolldown/createBuildPipeline.js.map +1 -1
- package/lib/scripts/build.js +45 -36
- package/lib/scripts/build.js.map +1 -1
- package/lib/types/config/baseConfig.d.ts +16 -0
- package/lib/types/config/baseConfig.d.ts.map +1 -1
- package/lib/types/rolldown/config.d.ts +4 -1
- package/lib/types/rolldown/config.d.ts.map +1 -1
- package/lib/types/rolldown/createBuildPipeline.d.ts +1 -1
- package/lib/types/rolldown/createBuildPipeline.d.ts.map +1 -1
- package/lib/types/scripts/build.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/bin/run-watch.ts +1 -1
- package/src/config/baseConfig.test.ts +10 -0
- package/src/config/baseConfig.ts +17 -0
- package/src/rolldown/config.ts +19 -6
- package/src/rolldown/createBuildPipeline.ts +11 -1
- package/src/scripts/build.ts +59 -46
package/README.md
CHANGED
|
@@ -84,6 +84,58 @@ export default {
|
|
|
84
84
|
}
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
### Advanced build options
|
|
88
|
+
|
|
89
|
+
For non-library builds (Chrome extensions, CLI tools, serverless functions, Electron), you can override the default package.json-driven pipeline:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
export default {
|
|
93
|
+
build: {
|
|
94
|
+
// Explicit entries — skips package.json field detection
|
|
95
|
+
entries: [
|
|
96
|
+
{ input: 'src/background.ts', file: 'dist/background.js', format: 'iife', env: 'production' },
|
|
97
|
+
{ input: 'src/content.ts', file: 'dist/content.js', format: 'iife' },
|
|
98
|
+
{ input: 'src/popup.ts', file: 'dist/popup.js', format: 'es' },
|
|
99
|
+
],
|
|
100
|
+
|
|
101
|
+
// Bundle all dependencies (no externals)
|
|
102
|
+
bundleAll: true,
|
|
103
|
+
|
|
104
|
+
// Copy static assets after build
|
|
105
|
+
copyFiles: [
|
|
106
|
+
{ from: 'src/manifest.json', to: 'dist/manifest.json' },
|
|
107
|
+
{ from: 'src/popup.html', to: 'dist/popup.html' },
|
|
108
|
+
],
|
|
109
|
+
|
|
110
|
+
// Inject text at top/bottom of output
|
|
111
|
+
banner: '#!/usr/bin/env node',
|
|
112
|
+
footer: '// Generated by @vitus-labs/tools-rolldown',
|
|
113
|
+
|
|
114
|
+
// Resolve aliases
|
|
115
|
+
alias: {
|
|
116
|
+
'@': './src',
|
|
117
|
+
'node:crypto': './src/polyfills/crypto.ts',
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// Custom rolldown plugins (appended to built-in ones)
|
|
121
|
+
plugins: [],
|
|
122
|
+
|
|
123
|
+
// Disable declarations for non-library builds
|
|
124
|
+
typescript: false,
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
| Option | Type | Default | Description |
|
|
130
|
+
|---|---|---|---|
|
|
131
|
+
| `entries` | `Array<{ input, file, format?, env?, platform? }>` | `undefined` | Explicit entry points (bypasses package.json detection) |
|
|
132
|
+
| `bundleAll` | `boolean` | `false` | Bundle all dependencies instead of externalizing |
|
|
133
|
+
| `copyFiles` | `Array<{ from, to }>` | `undefined` | Copy static files/directories after build |
|
|
134
|
+
| `banner` | `string` | `undefined` | Text injected at the top of each output file |
|
|
135
|
+
| `footer` | `string` | `undefined` | Text injected at the bottom of each output file |
|
|
136
|
+
| `alias` | `Record<string, string>` | `undefined` | Resolve aliases for import remapping |
|
|
137
|
+
| `plugins` | `RolldownPlugin[]` | `[]` | Custom plugins appended to built-in ones |
|
|
138
|
+
|
|
87
139
|
## License
|
|
88
140
|
|
|
89
141
|
MIT
|
package/lib/bin/run-watch.js.map
CHANGED
|
@@ -1 +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,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EACL,mBAAmB,EACnB,MAAM,IAAI,cAAc,GACzB,MAAM,sBAAsB,CAAA;AAE7B,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;AACvB,MAAM,SAAS,GAAG,mBAAmB,EAAE,CAAA;AAEvC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,CAAA;AACpE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;AACrB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;AAEvB,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,
|
|
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,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EACL,mBAAmB,EACnB,MAAM,IAAI,cAAc,GACzB,MAAM,sBAAsB,CAAA;AAE7B,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;AACvB,MAAM,SAAS,GAAG,mBAAmB,EAAE,CAAA;AAEvC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,CAA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ACV,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","sourcesContent":["#!/usr/bin/env node\nimport chalk from 'chalk'\nimport { watch } from 'rolldown'\nimport { PKG } from '../config/index.js'\nimport {\n createBuildPipeline,\n config as rolldownConfig,\n} from '../rolldown/index.js'\n\nconst { log } = console\nconst allBuilds = createBuildPipeline()\n\nconst label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)\nconst dim = chalk.dim\nconst bold = chalk.bold\n\nconst watchConfigs = allBuilds.map((item: Record<string, any>) => {\n const { output, ...input } = rolldownConfig(item)\n return { ...input, output }\n})\n\nlog(`\\n${label('rolldown')} ${bold(PKG.name || '')} ${dim('watch mode')}\\n`)\nlog(dim('Waiting for changes...\\n'))\n\nconst watcher = watch(watchConfigs)\n\nwatcher.on('event', (event) => {\n switch (event.code) {\n case 'START':\n log(dim('Rebuilding...'))\n break\n case 'BUNDLE_END':\n log(\n ` ${chalk.green('+')} ${dim(event.output.join(', '))} ${dim(`(${event.duration}ms)`)}`,\n )\n event.result.close()\n break\n case 'END':\n log(`${chalk.green('Ready')} ${dim('- waiting for changes...')}\\n`)\n break\n case 'ERROR':\n log(`\\n${chalk.red('Error')} ${event.error.message || event.error}\\n`)\n if ('frame' in event.error && event.error.frame) {\n log(dim(String(event.error.frame)))\n }\n break\n }\n})\n\nprocess.on('SIGINT', () => {\n log(dim('\\nStopping...\\n'))\n watcher.close()\n process.exit(0)\n})\n"]}
|
package/lib/config/baseConfig.js
CHANGED
|
@@ -31,5 +31,13 @@ export default {
|
|
|
31
31
|
ReactDOM: 'react-dom',
|
|
32
32
|
styled: 'styled-components',
|
|
33
33
|
},
|
|
34
|
+
// Advanced build options
|
|
35
|
+
entries: undefined,
|
|
36
|
+
bundleAll: false,
|
|
37
|
+
copyFiles: undefined,
|
|
38
|
+
banner: undefined,
|
|
39
|
+
footer: undefined,
|
|
40
|
+
alias: undefined,
|
|
41
|
+
plugins: [],
|
|
34
42
|
};
|
|
35
43
|
//# sourceMappingURL=baseConfig.js.map
|
|
@@ -1 +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;
|
|
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;IAED,yBAAyB;IACzB,OAAO,EAAE,SAQI;IACb,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,SAAuD;IAClE,MAAM,EAAE,SAA+B;IACvC,MAAM,EAAE,SAA+B;IACvC,KAAK,EAAE,SAA+C;IACtD,OAAO,EAAE,EAAe;CACzB,CAAA","sourcesContent":["export default {\n sourceDir: 'src',\n outputDir: 'lib',\n typesDir: 'lib/types',\n typescript: true,\n esModulesOnly: false,\n replaceGlobals: true,\n visualise: {\n template: 'network',\n gzipSize: true,\n outputDir: 'analysis',\n },\n filesize: true,\n extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],\n include: ['src'],\n external: ['react/jsx-runtime'],\n exclude: [\n 'lib',\n 'node_modules/**',\n '**/__tests__/**',\n '**/__specs__/**',\n '**/__stories__/**',\n '*.test.*',\n '*.spec.*',\n '*.stories.*',\n 'stories.*',\n '*.story.*',\n ],\n globals: {\n react: 'React',\n ReactDOM: 'react-dom',\n styled: 'styled-components',\n },\n\n // Advanced build options\n entries: undefined as\n | {\n input: string\n file: string\n format?: string\n env?: string\n platform?: string\n }[]\n | undefined,\n bundleAll: false,\n copyFiles: undefined as { from: string; to: string }[] | undefined,\n banner: undefined as string | undefined,\n footer: undefined as string | undefined,\n alias: undefined as Record<string, string> | undefined,\n plugins: [] as unknown[],\n}\n"]}
|
package/lib/rolldown/config.js
CHANGED
|
@@ -54,19 +54,24 @@ const buildDefineOptions = (env, platform) => {
|
|
|
54
54
|
}
|
|
55
55
|
return defineOptions;
|
|
56
56
|
};
|
|
57
|
-
const rolldownConfig = ({ file, format, env, platform, }) => {
|
|
57
|
+
const rolldownConfig = ({ file, format, env, platform, input: entryInput, }) => {
|
|
58
58
|
const extensions = defineExtensions(platform);
|
|
59
|
-
const
|
|
59
|
+
const builtinPlugins = loadPlugins({ file });
|
|
60
|
+
const userPlugins = (CONFIG.plugins || []);
|
|
60
61
|
const define = buildDefineOptions(env, platform);
|
|
61
62
|
const lastSlash = file.lastIndexOf('/');
|
|
62
63
|
const dir = lastSlash >= 0 ? file.substring(0, lastSlash) : '.';
|
|
63
64
|
const entryFileName = lastSlash >= 0 ? file.substring(lastSlash + 1) : file;
|
|
65
|
+
const external = CONFIG.bundleAll
|
|
66
|
+
? []
|
|
67
|
+
: [...PKG.externalDependencies, ...CONFIG.external];
|
|
64
68
|
const buildOutput = {
|
|
65
|
-
input: CONFIG.sourceDir,
|
|
69
|
+
input: entryInput || CONFIG.sourceDir,
|
|
66
70
|
platform: mapPlatform(platform),
|
|
67
71
|
tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,
|
|
68
72
|
resolve: {
|
|
69
73
|
extensions,
|
|
74
|
+
alias: CONFIG.alias || undefined,
|
|
70
75
|
},
|
|
71
76
|
transform: define ? { define } : undefined,
|
|
72
77
|
output: {
|
|
@@ -76,16 +81,20 @@ const rolldownConfig = ({ file, format, env, platform, }) => {
|
|
|
76
81
|
globals: swapGlobals(CONFIG.globals),
|
|
77
82
|
sourcemap: true,
|
|
78
83
|
sourcemapIgnoreList: (relativeSourcePath) => relativeSourcePath.includes('node_modules'),
|
|
79
|
-
exports: ['cjs', 'umd'].includes(format)
|
|
84
|
+
exports: ['cjs', 'umd', 'iife'].includes(format)
|
|
85
|
+
? 'named'
|
|
86
|
+
: undefined,
|
|
80
87
|
name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,
|
|
81
88
|
esModule: true,
|
|
82
89
|
minify: env === 'production',
|
|
90
|
+
banner: CONFIG.banner || undefined,
|
|
91
|
+
footer: CONFIG.footer || undefined,
|
|
83
92
|
},
|
|
84
|
-
external
|
|
93
|
+
external,
|
|
85
94
|
treeshake: {
|
|
86
95
|
moduleSideEffects: false,
|
|
87
96
|
},
|
|
88
|
-
plugins,
|
|
97
|
+
plugins: [...builtinPlugins, ...userPlugins],
|
|
89
98
|
};
|
|
90
99
|
return buildOutput;
|
|
91
100
|
};
|
|
@@ -103,7 +112,9 @@ const buildDts = () => {
|
|
|
103
112
|
resolve: {
|
|
104
113
|
extensions: CONFIG.extensions,
|
|
105
114
|
},
|
|
106
|
-
external:
|
|
115
|
+
external: CONFIG.bundleAll
|
|
116
|
+
? []
|
|
117
|
+
: [...PKG.externalDependencies, ...CONFIG.external],
|
|
107
118
|
plugins: [...dts({ tsconfig: 'tsconfig.json' })],
|
|
108
119
|
output: {
|
|
109
120
|
dir,
|
|
@@ -1 +1 @@
|
|
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IAEzE,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,GAAG,MAAM,CAAC,SAAS,WAAW;QACrC,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE;YACP,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B;QACD,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,oBAAoB,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC3D,OAAO,EAAE,CAAC,GAAI,GAAG,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAsB,CAAC;QACtE,MAAM,EAAE;YACN,GAAG;YACH,cAAc,EAAE,aAAa;YAC7B,cAAc,EAAE,aAAa;YAC7B,MAAM,EAAE,IAAa;YACrB,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,IAAI;SACf;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,cAAc,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,CAAA","sourcesContent":["import { swapGlobals } from '@vitus-labs/tools-core'\nimport type { RolldownPlugin } from 'rolldown'\nimport { dts } from 'rolldown-plugin-dts'\nimport filesize from 'rollup-plugin-filesize'\nimport { visualizer } from 'rollup-plugin-visualizer'\nimport { CONFIG, PKG, PLATFORMS } from '../config/index.js'\n\nconst defineExtensions = (platform: string) => {\n const platformExtensions: string[] = []\n\n if ((PLATFORMS as readonly string[]).includes(platform)) {\n CONFIG.extensions.forEach((item: string) => {\n platformExtensions.push(`.${platform}${item}`)\n })\n }\n\n return platformExtensions.concat(CONFIG.extensions)\n}\n\nconst mapPlatform = (\n platform: string,\n): 'node' | 'browser' | 'neutral' | undefined => {\n if (platform === 'node') return 'node'\n if (platform === 'browser') return 'browser'\n return 'neutral'\n}\n\nconst loadPlugins = ({ file }: { file: string }) => {\n const plugins: RolldownPlugin[] = []\n\n // generate visualised graphs in dist folder\n if (CONFIG.visualise) {\n const filePath = file.split('/')\n const fileName = filePath.pop()\n\n const visualiserOptions = {\n title: `${PKG.name} - ${fileName}`,\n filename: `${filePath.join('/')}/${\n CONFIG.visualise.outputDir\n }/${fileName}.html`,\n template: CONFIG.visualise.template,\n gzipSize: CONFIG.visualise.gzipSize,\n }\n\n plugins.push(visualizer(visualiserOptions) as RolldownPlugin)\n }\n\n if (CONFIG.filesize) {\n plugins.push(filesize() as RolldownPlugin)\n }\n\n return plugins\n}\n\nconst buildDefineOptions = (env: string, platform: string) => {\n if (!CONFIG.replaceGlobals) return undefined\n\n const defineOptions: Record<string, string> = {\n __VERSION__: JSON.stringify(PKG.version),\n __NODE__: JSON.stringify(platform === 'node'),\n __WEB__: JSON.stringify(\n ['node', 'browser', 'universal'].includes(platform),\n ),\n __BROWSER__: JSON.stringify(platform === 'browser'),\n __NATIVE__: JSON.stringify(platform === 'native'),\n __CLIENT__: JSON.stringify(['native', 'browser'].includes(platform)),\n }\n\n if (env === 'production') {\n defineOptions['process.env.NODE_ENV'] = JSON.stringify(env)\n }\n\n return defineOptions\n}\n\nconst rolldownConfig = ({\n file,\n format,\n env,\n platform,\n}: Record<string, any>) => {\n const extensions = defineExtensions(platform)\n const plugins = loadPlugins({ file })\n const define = buildDefineOptions(env, platform)\n\n const lastSlash = file.lastIndexOf('/')\n const dir = lastSlash >= 0 ? file.substring(0, lastSlash) : '.'\n const entryFileName = lastSlash >= 0 ? file.substring(lastSlash + 1) : file\n\n const buildOutput = {\n input: CONFIG.sourceDir,\n platform: mapPlatform(platform),\n tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,\n resolve: {\n extensions,\n },\n transform: define ? { define } : undefined,\n output: {\n dir,\n entryFileNames: entryFileName,\n format,\n globals: swapGlobals(CONFIG.globals),\n sourcemap: true,\n sourcemapIgnoreList: (relativeSourcePath: string) =>\n relativeSourcePath.includes('node_modules'),\n exports: ['cjs', 'umd'].includes(format) ? ('named' as const) : undefined,\n name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,\n esModule: true,\n minify: env === 'production',\n },\n external: [...PKG.externalDependencies, ...CONFIG.external],\n treeshake: {\n moduleSideEffects: false,\n },\n plugins,\n }\n\n return buildOutput\n}\n\nconst buildDts = () => {\n const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings\n\n if (!CONFIG.typescript || !typesFilePath) return null\n\n const lastSlash = typesFilePath.lastIndexOf('/')\n const dir = lastSlash >= 0 ? typesFilePath.substring(0, lastSlash) : '.'\n const entryFileName =\n lastSlash >= 0 ? typesFilePath.substring(lastSlash + 1) : typesFilePath\n\n return {\n file: typesFilePath,\n input: `${CONFIG.sourceDir}/index.ts`,\n tsconfig: 'tsconfig.json',\n resolve: {\n extensions: CONFIG.extensions,\n },\n external: [...PKG.externalDependencies, ...CONFIG.external],\n plugins: [...(dts({ tsconfig: 'tsconfig.json' }) as RolldownPlugin[])],\n output: {\n dir,\n entryFileNames: entryFileName,\n chunkFileNames: '[name].d.ts',\n format: 'es' as const,\n sourcemap: false,\n esModule: true,\n },\n }\n}\n\nexport default rolldownConfig\nexport { buildDts }\n"]}
|
|
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,IAA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,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,oBAAoB,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrD,OAAO,EAAE,CAAC,GAAI,GAAG,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAsB,CAAC;QACtE,MAAM,EAAE;YACN,GAAG;YACH,cAAc,EAAE,aAAa;YAC7B,cAAc,EAAE,aAAa;YAC7B,MAAM,EAAE,IAAa;YACrB,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,IAAI;SACf;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,cAAc,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,CAAA","sourcesContent":["import { swapGlobals } from '@vitus-labs/tools-core'\nimport type { RolldownPlugin } from 'rolldown'\nimport { dts } from 'rolldown-plugin-dts'\nimport filesize from 'rollup-plugin-filesize'\nimport { visualizer } from 'rollup-plugin-visualizer'\nimport { CONFIG, PKG, PLATFORMS } from '../config/index.js'\n\nconst defineExtensions = (platform: string) => {\n const platformExtensions: string[] = []\n\n if ((PLATFORMS as readonly string[]).includes(platform)) {\n CONFIG.extensions.forEach((item: string) => {\n platformExtensions.push(`.${platform}${item}`)\n })\n }\n\n return platformExtensions.concat(CONFIG.extensions)\n}\n\nconst mapPlatform = (\n platform: string,\n): 'node' | 'browser' | 'neutral' | undefined => {\n if (platform === 'node') return 'node'\n if (platform === 'browser') return 'browser'\n return 'neutral'\n}\n\nconst loadPlugins = ({ file }: { file: string }) => {\n const plugins: RolldownPlugin[] = []\n\n // generate visualised graphs in dist folder\n if (CONFIG.visualise) {\n const filePath = file.split('/')\n const fileName = filePath.pop()\n\n const visualiserOptions = {\n title: `${PKG.name} - ${fileName}`,\n filename: `${filePath.join('/')}/${\n CONFIG.visualise.outputDir\n }/${fileName}.html`,\n template: CONFIG.visualise.template,\n gzipSize: CONFIG.visualise.gzipSize,\n }\n\n plugins.push(visualizer(visualiserOptions) as RolldownPlugin)\n }\n\n if (CONFIG.filesize) {\n plugins.push(filesize() as RolldownPlugin)\n }\n\n return plugins\n}\n\nconst buildDefineOptions = (env: string, platform: string) => {\n if (!CONFIG.replaceGlobals) return undefined\n\n const defineOptions: Record<string, string> = {\n __VERSION__: JSON.stringify(PKG.version),\n __NODE__: JSON.stringify(platform === 'node'),\n __WEB__: JSON.stringify(\n ['node', 'browser', 'universal'].includes(platform),\n ),\n __BROWSER__: JSON.stringify(platform === 'browser'),\n __NATIVE__: JSON.stringify(platform === 'native'),\n __CLIENT__: JSON.stringify(['native', 'browser'].includes(platform)),\n }\n\n if (env === 'production') {\n defineOptions['process.env.NODE_ENV'] = JSON.stringify(env)\n }\n\n return defineOptions\n}\n\nconst rolldownConfig = ({\n file,\n format,\n env,\n platform,\n input: entryInput,\n}: Record<string, any>) => {\n const extensions = defineExtensions(platform)\n const builtinPlugins = loadPlugins({ file })\n const userPlugins = (CONFIG.plugins || []) as RolldownPlugin[]\n const define = buildDefineOptions(env, platform)\n\n const lastSlash = file.lastIndexOf('/')\n const dir = lastSlash >= 0 ? file.substring(0, lastSlash) : '.'\n const entryFileName = lastSlash >= 0 ? file.substring(lastSlash + 1) : file\n\n const external = CONFIG.bundleAll\n ? []\n : [...PKG.externalDependencies, ...CONFIG.external]\n\n const buildOutput = {\n input: entryInput || CONFIG.sourceDir,\n platform: mapPlatform(platform),\n tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,\n resolve: {\n extensions,\n alias: CONFIG.alias || undefined,\n },\n transform: define ? { define } : undefined,\n output: {\n dir,\n entryFileNames: entryFileName,\n format,\n globals: swapGlobals(CONFIG.globals),\n sourcemap: true,\n sourcemapIgnoreList: (relativeSourcePath: string) =>\n relativeSourcePath.includes('node_modules'),\n exports: ['cjs', 'umd', 'iife'].includes(format)\n ? ('named' as const)\n : undefined,\n name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,\n esModule: true,\n minify: env === 'production',\n banner: CONFIG.banner || undefined,\n footer: CONFIG.footer || undefined,\n },\n external,\n treeshake: {\n moduleSideEffects: false,\n },\n plugins: [...builtinPlugins, ...userPlugins],\n }\n\n return buildOutput\n}\n\nconst buildDts = () => {\n const typesFilePath = PKG?.exports?.types || PKG.types || PKG.typings\n\n if (!CONFIG.typescript || !typesFilePath) return null\n\n const lastSlash = typesFilePath.lastIndexOf('/')\n const dir = lastSlash >= 0 ? typesFilePath.substring(0, lastSlash) : '.'\n const entryFileName =\n lastSlash >= 0 ? typesFilePath.substring(lastSlash + 1) : typesFilePath\n\n return {\n file: typesFilePath,\n input: `${CONFIG.sourceDir}/index.ts`,\n tsconfig: 'tsconfig.json',\n resolve: {\n extensions: CONFIG.extensions,\n },\n external: CONFIG.bundleAll\n ? []\n : [...PKG.externalDependencies, ...CONFIG.external],\n plugins: [...(dts({ tsconfig: 'tsconfig.json' }) as RolldownPlugin[])],\n output: {\n dir,\n entryFileNames: entryFileName,\n chunkFileNames: '[name].d.ts',\n format: 'es' as const,\n sourcemap: false,\n esModule: true,\n },\n }\n}\n\nexport default rolldownConfig\nexport { buildDts }\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PKG } from '../config/index.js';
|
|
1
|
+
import { CONFIG, PKG } from '../config/index.js';
|
|
2
2
|
const isESModuleOnly = PKG.type === 'module';
|
|
3
3
|
const hasDifferentNativeBuild = () => {
|
|
4
4
|
return PKG['react-native'] !== PKG.module;
|
|
@@ -125,6 +125,15 @@ const createBrowserBuildVariants = () => {
|
|
|
125
125
|
return result;
|
|
126
126
|
};
|
|
127
127
|
const createBuildPipeline = () => {
|
|
128
|
+
if (Array.isArray(CONFIG.entries) && CONFIG.entries.length > 0) {
|
|
129
|
+
return CONFIG.entries.map((entry) => ({
|
|
130
|
+
format: entry.format || 'es',
|
|
131
|
+
env: entry.env || 'development',
|
|
132
|
+
platform: entry.platform || 'universal',
|
|
133
|
+
file: entry.file,
|
|
134
|
+
input: entry.input,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
128
137
|
return [...createBasicBuildVariants(), ...createBrowserBuildVariants()];
|
|
129
138
|
};
|
|
130
139
|
export default createBuildPipeline;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildPipeline.js","sourceRoot":"","sources":["../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"createBuildPipeline.js","sourceRoot":"","sources":["../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AAE5C,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,CAAA;IAClD,CAAC,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,cAAc,GAGhB;IACF,IAAI,EAAE;QACJ,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;QACrC,GAAG,EAAE,aAAa;QAClB,QAAQ,EAAE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AAG,EAAE,KAAK,CAAC,GAAG,IAAI,aAAa;YAC/B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,WAAW;YACvC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC,CAAA;IACL,CAAC;IAED,OAAO,CAAC,GAAG,wBAAwB,EAAE,EAAE,GAAG,0BAA0B,EAAE,CAAC,CAAA;AACzE,CAAC,CAAA;AAED,eAAe,mBAAmB,CAAA","sourcesContent":["import { CONFIG, PKG } from '../config/index.js'\n\nconst isESModuleOnly = PKG.type === 'module'\n\nconst hasDifferentNativeBuild = () => {\n return PKG['react-native'] !== PKG.module\n}\n\nconst hasDifferentBrowserBuild = (type: string) => {\n if (!PKG.browser) return false\n\n return Object.entries(PKG.browser as Record<string, string>).some(\n ([key, value]) => {\n const source = key.substring(2)\n const output = value.substring(2)\n\n return source !== PKG[type] && source !== output\n },\n )\n}\n\nconst BUILD_VARIANTS: Record<\n string,\n { format: string; env: string; platform?: string }\n> = {\n main: {\n format: isESModuleOnly ? 'es' : 'cjs',\n env: 'development',\n platform: 'universal',\n },\n module: {\n format: 'es',\n env: 'development',\n platform: 'universal',\n },\n 'react-native': {\n format: 'es',\n env: 'development',\n platform: 'native',\n },\n 'umd:main': { format: 'umd', env: 'development' },\n unpkg: { format: 'umd', env: 'production' },\n}\n\nconst getExportsOptions = () => {\n const exportsOptions = PKG.exports\n\n if (!exportsOptions) return []\n\n if (typeof exportsOptions === 'string') {\n return [\n {\n file: PKG.exports,\n ...BUILD_VARIANTS.module,\n },\n ]\n }\n\n if (typeof exportsOptions === 'object') {\n const result: Record<string, any>[] = []\n\n if (exportsOptions.import) {\n result.push({\n file: exportsOptions.import,\n ...BUILD_VARIANTS.module,\n })\n }\n\n if (exportsOptions.require) {\n result.push({\n file: exportsOptions.require,\n ...BUILD_VARIANTS.main,\n })\n }\n\n if (exportsOptions.node) {\n result.push({\n file: exportsOptions.node,\n ...BUILD_VARIANTS.module,\n platform: 'node',\n })\n }\n\n if (exportsOptions.default) {\n result.push({\n file: exportsOptions.default,\n ...BUILD_VARIANTS.module,\n })\n }\n\n return result\n }\n\n return []\n}\n\nconst createBasicBuildVariants = () => {\n let result: Record<string, any>[] = []\n\n if (isESModuleOnly) result = [...getExportsOptions()]\n\n Object.keys(BUILD_VARIANTS).forEach((key) => {\n const PKGOutDir = PKG[key]\n\n if (PKGOutDir) {\n const hasBrowserBuild = hasDifferentBrowserBuild(key)\n const hasNativeBuild = hasDifferentNativeBuild()\n\n // create a helper function for adding a build variant to an array\n const add = (props = {}) => {\n result.push({ ...BUILD_VARIANTS[key], file: PKGOutDir, ...props })\n }\n\n if (key === 'react-native') {\n // add a separate RN build only if output path differs from module path\n if (hasNativeBuild) {\n add()\n }\n } else if (hasBrowserBuild) {\n // if has a different browser build, set default platform to node\n // as there is going to be created a separate browser build as well\n add({ platform: 'node' })\n } else {\n add()\n }\n }\n })\n\n return result\n}\n\nconst createBrowserBuildVariants = () => {\n const result: Record<string, any>[] = []\n if (!PKG.browser) return result\n\n Object.entries(PKG.browser as Record<string, string>).forEach(\n ([key, value]) => {\n const source = key.substring(2) // strip './' from the beginning of path\n const output = value.substring(2) // strip './' from the beginning of path\n\n Object.keys(BUILD_VARIANTS).forEach((item) => {\n if (PKG[item] === source && source !== output) {\n result.push({\n ...BUILD_VARIANTS[item],\n file: output,\n platform: 'browser',\n })\n }\n })\n },\n )\n\n return result\n}\n\nconst createBuildPipeline = () => {\n if (Array.isArray(CONFIG.entries) && CONFIG.entries.length > 0) {\n return CONFIG.entries.map((entry: Record<string, string | undefined>) => ({\n format: entry.format || 'es',\n env: entry.env || 'development',\n platform: entry.platform || 'universal',\n file: entry.file,\n input: entry.input,\n }))\n }\n\n return [...createBasicBuildVariants(), ...createBrowserBuildVariants()]\n}\n\nexport default createBuildPipeline\n"]}
|
package/lib/scripts/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, renameSync, statSync, unlinkSync } from 'node:fs';
|
|
1
|
+
import { cpSync, readdirSync, renameSync, statSync, unlinkSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { rimraf } from 'rimraf';
|
|
@@ -12,6 +12,7 @@ const FORMAT_LABEL = {
|
|
|
12
12
|
cjs: 'CJS',
|
|
13
13
|
es: 'ESM',
|
|
14
14
|
umd: 'UMD',
|
|
15
|
+
iife: 'IIFE',
|
|
15
16
|
};
|
|
16
17
|
const label = (text) => chalk.bold.bgCyan.black(` ${text} `);
|
|
17
18
|
const dim = chalk.dim;
|
|
@@ -44,6 +45,47 @@ const createBuilds = async () => {
|
|
|
44
45
|
});
|
|
45
46
|
return p;
|
|
46
47
|
};
|
|
48
|
+
const copyStaticFiles = () => {
|
|
49
|
+
if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0)
|
|
50
|
+
return;
|
|
51
|
+
log(`\n${dim('Copying')} static files...\n`);
|
|
52
|
+
for (const { from, to } of CONFIG.copyFiles) {
|
|
53
|
+
cpSync(from, to, { recursive: true });
|
|
54
|
+
log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const fixDtsCodeSplit = (outDir, entryName) => {
|
|
58
|
+
const entryPath = join(outDir, entryName);
|
|
59
|
+
const allDts = readdirSync(outDir).filter((f) => f.endsWith('.d.ts') && f !== entryName);
|
|
60
|
+
if (allDts.length !== 1 || !allDts[0])
|
|
61
|
+
return;
|
|
62
|
+
const chunkPath = join(outDir, allDts[0]);
|
|
63
|
+
const chunkSize = statSync(chunkPath).size;
|
|
64
|
+
const entrySize = statSync(entryPath).size;
|
|
65
|
+
if (chunkSize > entrySize) {
|
|
66
|
+
unlinkSync(entryPath);
|
|
67
|
+
renameSync(chunkPath, entryPath);
|
|
68
|
+
try {
|
|
69
|
+
unlinkSync(`${entryPath}.map`);
|
|
70
|
+
renameSync(`${chunkPath}.map`, `${entryPath}.map`);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// sourcemap may not exist
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const generateDeclarations = async () => {
|
|
78
|
+
const dtsFile = buildDts();
|
|
79
|
+
if (!dtsFile)
|
|
80
|
+
return;
|
|
81
|
+
log(`\n${dim('Generating')} declarations...`);
|
|
82
|
+
const tscStart = performance.now();
|
|
83
|
+
const { output, file, ...input } = dtsFile;
|
|
84
|
+
await build({ inputOptions: input, outputOptions: output });
|
|
85
|
+
fixDtsCodeSplit(output.dir, output.entryFileNames);
|
|
86
|
+
const tscDuration = Math.round(performance.now() - tscStart);
|
|
87
|
+
log(` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`);
|
|
88
|
+
};
|
|
47
89
|
const runBuild = async () => {
|
|
48
90
|
const start = performance.now();
|
|
49
91
|
log(`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\n`);
|
|
@@ -51,41 +93,8 @@ const runBuild = async () => {
|
|
|
51
93
|
rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`);
|
|
52
94
|
log(`${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\n`);
|
|
53
95
|
await createBuilds();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
log(`\n${dim('Generating')} declarations...`);
|
|
57
|
-
const tscStart = performance.now();
|
|
58
|
-
const { output, file, ...input } = dtsFile;
|
|
59
|
-
await build({ inputOptions: input, outputOptions: output });
|
|
60
|
-
// rolldown-plugin-dts may code-split into entry + chunk where the entry
|
|
61
|
-
// is empty and the chunk has all declarations. Fix by replacing the entry
|
|
62
|
-
// with the chunk content.
|
|
63
|
-
const outDir = output.dir;
|
|
64
|
-
const entryName = output.entryFileNames;
|
|
65
|
-
const entryPath = join(outDir, entryName);
|
|
66
|
-
const allDts = readdirSync(outDir).filter((f) => f.endsWith('.d.ts') && f !== entryName);
|
|
67
|
-
if (allDts.length === 1 && allDts[0]) {
|
|
68
|
-
const chunkPath = join(outDir, allDts[0]);
|
|
69
|
-
const chunkSize = statSync(chunkPath).size;
|
|
70
|
-
const entrySize = statSync(entryPath).size;
|
|
71
|
-
if (chunkSize > entrySize) {
|
|
72
|
-
unlinkSync(entryPath);
|
|
73
|
-
renameSync(chunkPath, entryPath);
|
|
74
|
-
// also handle sourcemap
|
|
75
|
-
const chunkMap = `${chunkPath}.map`;
|
|
76
|
-
const entryMap = `${entryPath}.map`;
|
|
77
|
-
try {
|
|
78
|
-
unlinkSync(entryMap);
|
|
79
|
-
renameSync(chunkMap, entryMap);
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// sourcemap may not exist
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const tscDuration = Math.round(performance.now() - tscStart);
|
|
87
|
-
log(` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`);
|
|
88
|
-
}
|
|
96
|
+
copyStaticFiles();
|
|
97
|
+
await generateDeclarations();
|
|
89
98
|
const total = Math.round(performance.now() - start);
|
|
90
99
|
log(`\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\n`);
|
|
91
100
|
};
|
package/lib/scripts/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/scripts/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/scripts/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAA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AAG,KAAK,IAAI,EAAE;IAC1B,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;IAE/B,GAAG,CACD,KAAK,KAAK,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,IAAI,OAAO,EAAE,CAAC,IAAI,CACxF,CAAA;IAED,GAAG,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,SAAS,GAAG,CAAC,CAAA;IAC9C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC,CAAA;IAEnD,GAAG,CACD,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;IACpB,eAAe,EAAE,CAAA;IACjB,MAAM,oBAAoB,EAAE,CAAA;IAE5B,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","sourcesContent":["import { cpSync, readdirSync, renameSync, statSync, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\nimport chalk from 'chalk'\nimport { rimraf } from 'rimraf'\nimport { rolldown } from 'rolldown'\nimport { CONFIG, PKG } from '../config/index.js'\nimport {\n buildDts,\n createBuildPipeline,\n config as rolldownConfig,\n} from '../rolldown/index.js'\n\nconst { log } = console\nconst allBuilds = createBuildPipeline()\nconst allBuildsCount = allBuilds.length\n\nconst FORMAT_LABEL: Record<string, string> = {\n cjs: 'CJS',\n es: 'ESM',\n umd: 'UMD',\n iife: 'IIFE',\n}\n\nconst label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)\nconst dim = chalk.dim\nconst bold = chalk.bold\n\nasync function build({\n inputOptions,\n outputOptions,\n}: {\n inputOptions: any\n outputOptions: any\n}) {\n const bundle = await rolldown(inputOptions)\n await bundle.write(outputOptions)\n await bundle.close()\n}\n\nconst createBuilds = async () => {\n let p = Promise.resolve()\n\n allBuilds.forEach((item: Record<string, any>) => {\n const { output, ...input } = rolldownConfig(item)\n const format = FORMAT_LABEL[output.format] || output.format\n p = p.then(() => {\n const start = performance.now()\n\n return build({ inputOptions: input, outputOptions: output })\n .then(() => {\n const duration = Math.round(performance.now() - start)\n log(\n ` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`,\n )\n })\n .catch((e) => {\n log(`\\n${chalk.bold.red('Build failed')}`)\n log(chalk.gray(` Format: ${format}`))\n log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`))\n log(e)\n throw e\n })\n })\n })\n\n return p\n}\n\nconst copyStaticFiles = () => {\n if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0) return\n\n log(`\\n${dim('Copying')} static files...\\n`)\n for (const { from, to } of CONFIG.copyFiles as {\n from: string\n to: string\n }[]) {\n cpSync(from, to, { recursive: true })\n log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`)\n }\n}\n\nconst fixDtsCodeSplit = (outDir: string, entryName: string) => {\n const entryPath = join(outDir, entryName)\n const allDts = readdirSync(outDir).filter(\n (f) => f.endsWith('.d.ts') && f !== entryName,\n )\n\n if (allDts.length !== 1 || !allDts[0]) return\n\n const chunkPath = join(outDir, allDts[0])\n const chunkSize = statSync(chunkPath).size\n const entrySize = statSync(entryPath).size\n\n if (chunkSize > entrySize) {\n unlinkSync(entryPath)\n renameSync(chunkPath, entryPath)\n try {\n unlinkSync(`${entryPath}.map`)\n renameSync(`${chunkPath}.map`, `${entryPath}.map`)\n } catch {\n // sourcemap may not exist\n }\n }\n}\n\nconst generateDeclarations = async () => {\n const dtsFile = buildDts()\n if (!dtsFile) return\n\n log(`\\n${dim('Generating')} declarations...`)\n const tscStart = performance.now()\n\n const { output, file, ...input } = dtsFile\n await build({ inputOptions: input, outputOptions: output })\n fixDtsCodeSplit(output.dir as string, output.entryFileNames as string)\n\n const tscDuration = Math.round(performance.now() - tscStart)\n log(\n ` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`,\n )\n}\n\nconst runBuild = async () => {\n const start = performance.now()\n\n log(\n `\\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\\n`,\n )\n\n log(`${dim('Cleaning')} ${CONFIG.outputDir}/`)\n rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`)\n\n log(\n `${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\\n`,\n )\n\n await createBuilds()\n copyStaticFiles()\n await generateDeclarations()\n\n const total = Math.round(performance.now() - start)\n log(`\\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\\n`)\n}\n\nexport { runBuild }\n"]}
|
|
@@ -20,6 +20,22 @@ declare const _default: {
|
|
|
20
20
|
ReactDOM: string;
|
|
21
21
|
styled: string;
|
|
22
22
|
};
|
|
23
|
+
entries: {
|
|
24
|
+
input: string;
|
|
25
|
+
file: string;
|
|
26
|
+
format?: string;
|
|
27
|
+
env?: string;
|
|
28
|
+
platform?: string;
|
|
29
|
+
}[] | undefined;
|
|
30
|
+
bundleAll: boolean;
|
|
31
|
+
copyFiles: {
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
}[] | undefined;
|
|
35
|
+
banner: string | undefined;
|
|
36
|
+
footer: string | undefined;
|
|
37
|
+
alias: Record<string, string> | undefined;
|
|
38
|
+
plugins: unknown[];
|
|
23
39
|
};
|
|
24
40
|
export default _default;
|
|
25
41
|
//# sourceMappingURL=baseConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseConfig.d.ts","sourceRoot":"","sources":["../../../src/config/baseConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"baseConfig.d.ts","sourceRoot":"","sources":["../../../src/config/baseConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;aAoCM;QACE,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;KAClB,EAAE,GACH,SAAS;;eAEW;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,SAAS;YAC7C,MAAM,GAAG,SAAS;YAClB,MAAM,GAAG,SAAS;WACnB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;aACvC,OAAO,EAAE;;AAjD1B,wBAkDC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { RolldownPlugin } from 'rolldown';
|
|
2
|
-
declare const rolldownConfig: ({ file, format, env, platform, }: Record<string, any>) => {
|
|
2
|
+
declare const rolldownConfig: ({ file, format, env, platform, input: entryInput, }: Record<string, any>) => {
|
|
3
3
|
input: any;
|
|
4
4
|
platform: "browser" | "node" | "neutral" | undefined;
|
|
5
5
|
tsconfig: string | undefined;
|
|
6
6
|
resolve: {
|
|
7
7
|
extensions: string[];
|
|
8
|
+
alias: any;
|
|
8
9
|
};
|
|
9
10
|
transform: {
|
|
10
11
|
define: Record<string, string>;
|
|
@@ -20,6 +21,8 @@ declare const rolldownConfig: ({ file, format, env, platform, }: Record<string,
|
|
|
20
21
|
name: any;
|
|
21
22
|
esModule: boolean;
|
|
22
23
|
minify: boolean;
|
|
24
|
+
banner: any;
|
|
25
|
+
footer: any;
|
|
23
26
|
};
|
|
24
27
|
external: any[];
|
|
25
28
|
treeshake: {
|
|
@@ -1 +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;AA0E9C,QAAA,MAAM,cAAc,GAAI,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/rolldown/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AA0E9C,QAAA,MAAM,cAAc,GAAI,qDAMrB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;;;;;;;;;;;;;;kDA6B0B,MAAM;;;;;;;;;;;;;CAmBrD,CAAA;AAED,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;QA8Bb,CAAA;AAED,eAAe,cAAc,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildPipeline.d.ts","sourceRoot":"","sources":["../../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AA2JA,QAAA,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"createBuildPipeline.d.ts","sourceRoot":"","sources":["../../../src/rolldown/createBuildPipeline.ts"],"names":[],"mappings":"AA2JA,QAAA,MAAM,mBAAmB,WAYxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AA0HA,QAAA,MAAM,QAAQ,qBAoBb,CAAA;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/tools-rolldown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1-alpha.0+55197fb",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@vitus-labs/tools-core": "1.
|
|
40
|
+
"@vitus-labs/tools-core": "1.12.1-alpha.0+55197fb",
|
|
41
41
|
"chalk": "^5.6.2",
|
|
42
42
|
"rimraf": "^6.1.3",
|
|
43
43
|
"rolldown": "^1.0.0-rc.9",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"rollup-plugin-visualizer": "^7.0.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@vitus-labs/tools-typescript": "1.
|
|
49
|
+
"@vitus-labs/tools-typescript": "1.12.1-alpha.0+55197fb",
|
|
50
50
|
"typescript": "^5.9.3"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "55197fba817ec0d61aae2d71cd82156029445d64"
|
|
53
53
|
}
|
package/src/bin/run-watch.ts
CHANGED
|
@@ -14,7 +14,7 @@ const label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)
|
|
|
14
14
|
const dim = chalk.dim
|
|
15
15
|
const bold = chalk.bold
|
|
16
16
|
|
|
17
|
-
const watchConfigs = allBuilds.map((item) => {
|
|
17
|
+
const watchConfigs = allBuilds.map((item: Record<string, any>) => {
|
|
18
18
|
const { output, ...input } = rolldownConfig(item)
|
|
19
19
|
return { ...input, output }
|
|
20
20
|
})
|
|
@@ -47,4 +47,14 @@ describe('baseConfig', () => {
|
|
|
47
47
|
it('should include react/jsx-runtime as external', () => {
|
|
48
48
|
expect(baseConfig.external).toContain('react/jsx-runtime')
|
|
49
49
|
})
|
|
50
|
+
|
|
51
|
+
it('should have safe defaults for advanced build options', () => {
|
|
52
|
+
expect(baseConfig.entries).toBeUndefined()
|
|
53
|
+
expect(baseConfig.bundleAll).toBe(false)
|
|
54
|
+
expect(baseConfig.copyFiles).toBeUndefined()
|
|
55
|
+
expect(baseConfig.banner).toBeUndefined()
|
|
56
|
+
expect(baseConfig.footer).toBeUndefined()
|
|
57
|
+
expect(baseConfig.alias).toBeUndefined()
|
|
58
|
+
expect(baseConfig.plugins).toEqual([])
|
|
59
|
+
})
|
|
50
60
|
})
|
package/src/config/baseConfig.ts
CHANGED
|
@@ -31,4 +31,21 @@ export default {
|
|
|
31
31
|
ReactDOM: 'react-dom',
|
|
32
32
|
styled: 'styled-components',
|
|
33
33
|
},
|
|
34
|
+
|
|
35
|
+
// Advanced build options
|
|
36
|
+
entries: undefined as
|
|
37
|
+
| {
|
|
38
|
+
input: string
|
|
39
|
+
file: string
|
|
40
|
+
format?: string
|
|
41
|
+
env?: string
|
|
42
|
+
platform?: string
|
|
43
|
+
}[]
|
|
44
|
+
| undefined,
|
|
45
|
+
bundleAll: false,
|
|
46
|
+
copyFiles: undefined as { from: string; to: string }[] | undefined,
|
|
47
|
+
banner: undefined as string | undefined,
|
|
48
|
+
footer: undefined as string | undefined,
|
|
49
|
+
alias: undefined as Record<string, string> | undefined,
|
|
50
|
+
plugins: [] as unknown[],
|
|
34
51
|
}
|
package/src/rolldown/config.ts
CHANGED
|
@@ -78,21 +78,28 @@ const rolldownConfig = ({
|
|
|
78
78
|
format,
|
|
79
79
|
env,
|
|
80
80
|
platform,
|
|
81
|
+
input: entryInput,
|
|
81
82
|
}: Record<string, any>) => {
|
|
82
83
|
const extensions = defineExtensions(platform)
|
|
83
|
-
const
|
|
84
|
+
const builtinPlugins = loadPlugins({ file })
|
|
85
|
+
const userPlugins = (CONFIG.plugins || []) as RolldownPlugin[]
|
|
84
86
|
const define = buildDefineOptions(env, platform)
|
|
85
87
|
|
|
86
88
|
const lastSlash = file.lastIndexOf('/')
|
|
87
89
|
const dir = lastSlash >= 0 ? file.substring(0, lastSlash) : '.'
|
|
88
90
|
const entryFileName = lastSlash >= 0 ? file.substring(lastSlash + 1) : file
|
|
89
91
|
|
|
92
|
+
const external = CONFIG.bundleAll
|
|
93
|
+
? []
|
|
94
|
+
: [...PKG.externalDependencies, ...CONFIG.external]
|
|
95
|
+
|
|
90
96
|
const buildOutput = {
|
|
91
|
-
input: CONFIG.sourceDir,
|
|
97
|
+
input: entryInput || CONFIG.sourceDir,
|
|
92
98
|
platform: mapPlatform(platform),
|
|
93
99
|
tsconfig: CONFIG.typescript ? 'tsconfig.json' : undefined,
|
|
94
100
|
resolve: {
|
|
95
101
|
extensions,
|
|
102
|
+
alias: CONFIG.alias || undefined,
|
|
96
103
|
},
|
|
97
104
|
transform: define ? { define } : undefined,
|
|
98
105
|
output: {
|
|
@@ -103,16 +110,20 @@ const rolldownConfig = ({
|
|
|
103
110
|
sourcemap: true,
|
|
104
111
|
sourcemapIgnoreList: (relativeSourcePath: string) =>
|
|
105
112
|
relativeSourcePath.includes('node_modules'),
|
|
106
|
-
exports: ['cjs', 'umd'].includes(format)
|
|
113
|
+
exports: ['cjs', 'umd', 'iife'].includes(format)
|
|
114
|
+
? ('named' as const)
|
|
115
|
+
: undefined,
|
|
107
116
|
name: ['umd', 'iife'].includes(format) ? PKG.bundleName : undefined,
|
|
108
117
|
esModule: true,
|
|
109
118
|
minify: env === 'production',
|
|
119
|
+
banner: CONFIG.banner || undefined,
|
|
120
|
+
footer: CONFIG.footer || undefined,
|
|
110
121
|
},
|
|
111
|
-
external
|
|
122
|
+
external,
|
|
112
123
|
treeshake: {
|
|
113
124
|
moduleSideEffects: false,
|
|
114
125
|
},
|
|
115
|
-
plugins,
|
|
126
|
+
plugins: [...builtinPlugins, ...userPlugins],
|
|
116
127
|
}
|
|
117
128
|
|
|
118
129
|
return buildOutput
|
|
@@ -135,7 +146,9 @@ const buildDts = () => {
|
|
|
135
146
|
resolve: {
|
|
136
147
|
extensions: CONFIG.extensions,
|
|
137
148
|
},
|
|
138
|
-
external:
|
|
149
|
+
external: CONFIG.bundleAll
|
|
150
|
+
? []
|
|
151
|
+
: [...PKG.externalDependencies, ...CONFIG.external],
|
|
139
152
|
plugins: [...(dts({ tsconfig: 'tsconfig.json' }) as RolldownPlugin[])],
|
|
140
153
|
output: {
|
|
141
154
|
dir,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PKG } from '../config/index.js'
|
|
1
|
+
import { CONFIG, PKG } from '../config/index.js'
|
|
2
2
|
|
|
3
3
|
const isESModuleOnly = PKG.type === 'module'
|
|
4
4
|
|
|
@@ -154,6 +154,16 @@ const createBrowserBuildVariants = () => {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
const createBuildPipeline = () => {
|
|
157
|
+
if (Array.isArray(CONFIG.entries) && CONFIG.entries.length > 0) {
|
|
158
|
+
return CONFIG.entries.map((entry: Record<string, string | undefined>) => ({
|
|
159
|
+
format: entry.format || 'es',
|
|
160
|
+
env: entry.env || 'development',
|
|
161
|
+
platform: entry.platform || 'universal',
|
|
162
|
+
file: entry.file,
|
|
163
|
+
input: entry.input,
|
|
164
|
+
}))
|
|
165
|
+
}
|
|
166
|
+
|
|
157
167
|
return [...createBasicBuildVariants(), ...createBrowserBuildVariants()]
|
|
158
168
|
}
|
|
159
169
|
|
package/src/scripts/build.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, renameSync, statSync, unlinkSync } from 'node:fs'
|
|
1
|
+
import { cpSync, readdirSync, renameSync, statSync, unlinkSync } from 'node:fs'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { rimraf } from 'rimraf'
|
|
@@ -18,6 +18,7 @@ const FORMAT_LABEL: Record<string, string> = {
|
|
|
18
18
|
cjs: 'CJS',
|
|
19
19
|
es: 'ESM',
|
|
20
20
|
umd: 'UMD',
|
|
21
|
+
iife: 'IIFE',
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)
|
|
@@ -39,7 +40,7 @@ async function build({
|
|
|
39
40
|
const createBuilds = async () => {
|
|
40
41
|
let p = Promise.resolve()
|
|
41
42
|
|
|
42
|
-
allBuilds.forEach((item) => {
|
|
43
|
+
allBuilds.forEach((item: Record<string, any>) => {
|
|
43
44
|
const { output, ...input } = rolldownConfig(item)
|
|
44
45
|
const format = FORMAT_LABEL[output.format] || output.format
|
|
45
46
|
p = p.then(() => {
|
|
@@ -65,6 +66,60 @@ const createBuilds = async () => {
|
|
|
65
66
|
return p
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
const copyStaticFiles = () => {
|
|
70
|
+
if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0) return
|
|
71
|
+
|
|
72
|
+
log(`\n${dim('Copying')} static files...\n`)
|
|
73
|
+
for (const { from, to } of CONFIG.copyFiles as {
|
|
74
|
+
from: string
|
|
75
|
+
to: string
|
|
76
|
+
}[]) {
|
|
77
|
+
cpSync(from, to, { recursive: true })
|
|
78
|
+
log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const fixDtsCodeSplit = (outDir: string, entryName: string) => {
|
|
83
|
+
const entryPath = join(outDir, entryName)
|
|
84
|
+
const allDts = readdirSync(outDir).filter(
|
|
85
|
+
(f) => f.endsWith('.d.ts') && f !== entryName,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if (allDts.length !== 1 || !allDts[0]) return
|
|
89
|
+
|
|
90
|
+
const chunkPath = join(outDir, allDts[0])
|
|
91
|
+
const chunkSize = statSync(chunkPath).size
|
|
92
|
+
const entrySize = statSync(entryPath).size
|
|
93
|
+
|
|
94
|
+
if (chunkSize > entrySize) {
|
|
95
|
+
unlinkSync(entryPath)
|
|
96
|
+
renameSync(chunkPath, entryPath)
|
|
97
|
+
try {
|
|
98
|
+
unlinkSync(`${entryPath}.map`)
|
|
99
|
+
renameSync(`${chunkPath}.map`, `${entryPath}.map`)
|
|
100
|
+
} catch {
|
|
101
|
+
// sourcemap may not exist
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const generateDeclarations = async () => {
|
|
107
|
+
const dtsFile = buildDts()
|
|
108
|
+
if (!dtsFile) return
|
|
109
|
+
|
|
110
|
+
log(`\n${dim('Generating')} declarations...`)
|
|
111
|
+
const tscStart = performance.now()
|
|
112
|
+
|
|
113
|
+
const { output, file, ...input } = dtsFile
|
|
114
|
+
await build({ inputOptions: input, outputOptions: output })
|
|
115
|
+
fixDtsCodeSplit(output.dir as string, output.entryFileNames as string)
|
|
116
|
+
|
|
117
|
+
const tscDuration = Math.round(performance.now() - tscStart)
|
|
118
|
+
log(
|
|
119
|
+
` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`,
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
68
123
|
const runBuild = async () => {
|
|
69
124
|
const start = performance.now()
|
|
70
125
|
|
|
@@ -80,50 +135,8 @@ const runBuild = async () => {
|
|
|
80
135
|
)
|
|
81
136
|
|
|
82
137
|
await createBuilds()
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (dtsFile) {
|
|
86
|
-
log(`\n${dim('Generating')} declarations...`)
|
|
87
|
-
const tscStart = performance.now()
|
|
88
|
-
|
|
89
|
-
const { output, file, ...input } = dtsFile
|
|
90
|
-
await build({ inputOptions: input, outputOptions: output })
|
|
91
|
-
|
|
92
|
-
// rolldown-plugin-dts may code-split into entry + chunk where the entry
|
|
93
|
-
// is empty and the chunk has all declarations. Fix by replacing the entry
|
|
94
|
-
// with the chunk content.
|
|
95
|
-
const outDir = output.dir as string
|
|
96
|
-
const entryName = output.entryFileNames as string
|
|
97
|
-
const entryPath = join(outDir, entryName)
|
|
98
|
-
const allDts = readdirSync(outDir).filter(
|
|
99
|
-
(f) => f.endsWith('.d.ts') && f !== entryName,
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
if (allDts.length === 1 && allDts[0]) {
|
|
103
|
-
const chunkPath = join(outDir, allDts[0])
|
|
104
|
-
const chunkSize = statSync(chunkPath).size
|
|
105
|
-
const entrySize = statSync(entryPath).size
|
|
106
|
-
|
|
107
|
-
if (chunkSize > entrySize) {
|
|
108
|
-
unlinkSync(entryPath)
|
|
109
|
-
renameSync(chunkPath, entryPath)
|
|
110
|
-
// also handle sourcemap
|
|
111
|
-
const chunkMap = `${chunkPath}.map`
|
|
112
|
-
const entryMap = `${entryPath}.map`
|
|
113
|
-
try {
|
|
114
|
-
unlinkSync(entryMap)
|
|
115
|
-
renameSync(chunkMap, entryMap)
|
|
116
|
-
} catch {
|
|
117
|
-
// sourcemap may not exist
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const tscDuration = Math.round(performance.now() - tscStart)
|
|
123
|
-
log(
|
|
124
|
-
` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(file)} ${dim(`(${tscDuration}ms)`)}`,
|
|
125
|
-
)
|
|
126
|
-
}
|
|
138
|
+
copyStaticFiles()
|
|
139
|
+
await generateDeclarations()
|
|
127
140
|
|
|
128
141
|
const total = Math.round(performance.now() - start)
|
|
129
142
|
log(`\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\n`)
|