|
1 | 1 | import polyfillNode from '@rolldown/plugin-node-polyfills' |
2 | 2 | import { minify as minifySwc } from '@swc/core' |
| 3 | +import { promises as fs } from 'node:fs' |
3 | 4 | import { createRequire } from 'node:module' |
4 | 5 | import path from 'node:path' |
5 | 6 | import { fileURLToPath } from 'node:url' |
@@ -52,15 +53,14 @@ export function createConfigsForPackage({ |
52 | 53 | * Released under the ${pkg.license} License. |
53 | 54 | */` |
54 | 55 |
|
55 | | - // TODO: |
56 | | - /* |
57 | 56 | const stubs = { |
58 | | - [`dist/${name}.cjs`]: `${name}.cjs.js`, |
59 | | - [`dist/${name}.mjs`]: `${name}.esm-bundler.js`, |
60 | | - [`dist/${name}.runtime.mjs`]: `${name}.runtime.esm-bundler.js`, |
61 | | - [`dist/${name}.prod.cjs`]: `${name}.cjs.prod.js` |
| 57 | + [resolve(`dist/${name}.cjs`)]: resolve(`dist/${name}.cjs.js`), |
| 58 | + [resolve(`dist/${name}.mjs`)]: resolve(`dist/${name}.esm-bundler.js`), |
| 59 | + [resolve(`dist/${name}.runtime.mjs`)]: resolve( |
| 60 | + `dist/${name}.runtime.esm-bundler.js` |
| 61 | + ), |
| 62 | + [resolve(`dist/${name}.prod.cjs`)]: resolve(`dist/${name}.cjs.prod.js`) |
62 | 63 | } |
63 | | - */ |
64 | 64 |
|
65 | 65 | const outputConfigs: Record<string, OutputOptions> = { |
66 | 66 | mjs: { |
@@ -138,6 +138,7 @@ export function createConfigsForPackage({ |
138 | 138 | console.log(pc.yellow(`invalid format: "${format}"`)) |
139 | 139 | process.exit(1) |
140 | 140 | } |
| 141 | + const rawFile = output.file |
141 | 142 |
|
142 | 143 | const isProductionBuild = |
143 | 144 | process.env.__DEV__ === 'false' || |
@@ -303,8 +304,28 @@ export function createConfigsForPackage({ |
303 | 304 | plugins: [ |
304 | 305 | ...resolveReplace(), |
305 | 306 | ...resolveNodePlugins(), |
306 | | - ...plugins |
307 | | - // TODO: stub |
| 307 | + ...plugins, |
| 308 | + { |
| 309 | + name: 'write-stub', |
| 310 | + async writeBundle() { |
| 311 | + if (rawFile == null) { |
| 312 | + return |
| 313 | + } |
| 314 | + const stub = stubs[rawFile] |
| 315 | + if (!stub) { |
| 316 | + return |
| 317 | + } |
| 318 | + |
| 319 | + const filename = path.basename(rawFile) |
| 320 | + const contents = |
| 321 | + format === 'cjs' |
| 322 | + ? `module.exports = require('./${filename}')` |
| 323 | + : `export * from './${filename}'` |
| 324 | + |
| 325 | + await fs.writeFile(stub, contents) |
| 326 | + // console.log(`created stub ${pc.bold(path.join('packages', target, 'dist', path.basename(stub)))}`) |
| 327 | + } |
| 328 | + } |
308 | 329 | ], |
309 | 330 | output, |
310 | 331 | treeshake: { |
|
0 commit comments