UNPKG

lbundle

Version:

Small zero-configuration bundler build on top of Rollup.js and SWC for NPM libraries

49 lines (46 loc) 1.69 kB
import path from 'path'; import { rollup } from 'rollup'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import { swc } from 'rollup-plugin-swc3'; import { typescriptPaths } from 'rollup-plugin-typescript-paths'; import PeerDepsExternalPlugin from 'rollup-plugin-peer-deps-external'; import json from '@rollup/plugin-json'; import { getSwcConfig } from './get-swc-config.mjs'; import { jsExtensions } from '../constants/js-extensions.mjs'; import { isNil } from '../utils/checks.mjs'; import { stylesExtensions } from '../constants/styles-extensions.mjs'; const bundleBinIfNeeded = async (ctx)=>{ const { pkg, pkgPath, options, binOutput } = ctx; if (isNil(pkg['bin:source']) || isNil(binOutput)) return; const bundle = await rollup({ input: path.resolve(options.cwd, pkg['bin:source']), plugins: [ PeerDepsExternalPlugin({ includeDependencies: true, packageJsonPath: pkgPath }), typescriptPaths({ preserveExtensions: true }), json(), swc({ ...getSwcConfig(ctx, binOutput), tsconfig: ctx.tsconfigPath ?? false }), commonjs({ extensions: jsExtensions }), nodeResolve({ rootDir: options.cwd, extensions: [ ...jsExtensions, ...stylesExtensions ] }) ] }); await bundle.write(binOutput); }; export { bundleBinIfNeeded }; //# sourceMappingURL=bundle-bin-if-needed.mjs.map