PackConfig is the software package packaging configuration interface, used to package service build artifacts into standard npm .tgz format packages.
interface PackConfig {
enable?: boolean;
outputs?: string | string[] | boolean;
packageJson?: (esmx: Esmx, pkg: Record<string, any>) => Promise<Record<string, any>>;
onBefore?: (esmx: Esmx, pkg: Record<string, any>) => Promise<void>;
onAfter?: (esmx: Esmx, pkg: Record<string, any>, file: Buffer) => Promise<void>;
}Enables or disables packaging functionality. When enabled, build artifacts will be packaged into standard npm .tgz format packages.
booleanfalseSpecifies the output package file path. Supports the following configuration methods:
string: Single output path, e.g., 'dist/versions/my-app.tgz'string[]: Multiple output paths, for generating multiple versions simultaneouslyboolean: true uses the default path 'dist/client/versions/latest.tgz'Callback function to customize package.json content. Called before packaging, used to customize the package.json content.
esmx: Esmx - Esmx instancepkg: Record<string, any> - Original package.json contentPromise<Record<string, any>> - Modified package.json contentCommon use cases:
Example:
packageJson: async (esmx, pkg) => {
pkg.name = 'my-app';
pkg.version = '1.0.0';
pkg.description = 'My App';
pkg.dependencies = {
'vue': '^3.0.0',
'express': '^4.17.1'
};
pkg.publishConfig = {
registry: 'https://registry.example.com'
};
return pkg;
}Pre-packaging preparation callback function.
esmx: Esmx - Esmx instancepkg: Record<string, any> - package.json contentPromise<void>Common use cases:
Example:
onBefore: async (esmx, pkg) => {
await fs.writeFile('dist/README.md', '# My App');
await fs.writeFile('dist/LICENSE', 'MIT License');
await runTests();
await generateDocs();
await cleanupTempFiles();
}Post-packaging processing callback function. Called after .tgz file generation, used to process packaging artifacts.
esmx: Esmx - Esmx instancepkg: Record<string, any> - package.json contentfile: Buffer - Packaged file contentPromise<void>Common use cases:
Example:
onAfter: async (esmx, pkg, file) => {
await publishToRegistry(file, {
registry: 'https://registry.example.com'
});
await uploadToServer(file, 'https://assets.example.com/packages');
await createGitTag(pkg.version);
await triggerDeploy(pkg.version);
}import type { EsmxOptions } from '@esmx/core';
export default {
modules: {
exports: [
'root:src/components/button.vue',
'root:src/utils/format.ts',
'pkg:vue',
'pkg:vue-router'
]
},
packs: {
enable: true,
outputs: [
'dist/versions/latest.tgz',
'dist/versions/1.0.0.tgz'
],
packageJson: async (esmx, pkg) => {
pkg.version = '1.0.0';
return pkg;
},
onBefore: async (esmx, pkg) => {
await fs.writeFile('dist/README.md', '# Your App\n\nModule export instructions...');
await runTypeCheck();
},
onAfter: async (esmx, pkg, file) => {
await publishToRegistry(file, {
registry: 'https://npm.your-registry.com/'
});
await uploadToServer(file, 'https://static.example.com/packages');
}
}
} satisfies EsmxOptions;