diff --git a/packages/nano-build/README.md b/packages/nano-build/README.md index b2a733eb..f12404c3 100644 --- a/packages/nano-build/README.md +++ b/packages/nano-build/README.md @@ -31,7 +31,6 @@ Add the following scripts to your `package.json`: entryPoints: ['src/main.ts'], outdir: 'dist', logLevel: 'info', - platform: 'node', target: 'es2020', minify: true, treeShaking: false, @@ -55,6 +54,7 @@ Add the following scripts to your `package.json`: ```js { ...defaultPreset, + platform: 'node', format: 'esm', cjs: true, mangleProps: '_$', @@ -67,8 +67,8 @@ Add the following scripts to your `package.json`: ```js { ...defaultPreset, - format: 'iife', platform: 'browser', + format: 'iife', mangleProps: '_$', treeShaking: true, sourcemap: false, @@ -90,8 +90,8 @@ Add the following scripts to your `package.json`: ...defaultPreset, entryPoints: ['site/_ts/*.ts'], outdir: 'dist/es', - format: 'iife', platform: 'browser', + format: 'iife', mangleProps: '_$', treeShaking: true, sourcemap: false, @@ -111,11 +111,13 @@ Add the following scripts to your `package.json`: ```js { ...defaultPreset, + platform: 'node', format: 'esm', treeShaking: true, - outfile: 'dist/main.mjs', mangleProps: '_$', - target: 'node20' + sourcemap: false, + sourcesContent: false, + target: 'node20', } ``` diff --git a/packages/nano-build/nano-build.cjs b/packages/nano-build/nano-build.cjs index d2294856..a909cce2 100755 --- a/packages/nano-build/nano-build.cjs +++ b/packages/nano-build/nano-build.cjs @@ -23,7 +23,6 @@ const defaultOptions = { entryPoints: ['src/main.ts'], outdir: 'dist', logLevel: 'info', - platform: 'node', target: 'es2020', minify: true, treeShaking: false, @@ -42,23 +41,17 @@ const defaultOptions = { }; const presetRecord = { - default: defaultOptions, - microservice: { - format: 'esm', - treeShaking: true, - outfile: 'dist/main.mjs', - mangleProps: '_$', - target: 'node20' - }, + default: {}, module: { + platform: 'node', format: 'esm', cjs: true, mangleProps: '_$', packages: 'external', }, pwa: { - format: 'iife', platform: 'browser', + format: 'iife', mangleProps: '_$', treeShaking: true, sourcemap: false, @@ -74,8 +67,8 @@ const presetRecord = { pmpa: { entryPoints: ['site/_ts/*.ts'], outdir: 'dist/es', - format: 'iife', platform: 'browser', + format: 'iife', mangleProps: '_$', treeShaking: true, sourcemap: false, @@ -88,6 +81,15 @@ const presetRecord = { 'safari11', ], }, + microservice: { + platform: 'node', + format: 'esm', + treeShaking: true, + mangleProps: '_$', + sourcemap: false, + sourcesContent: false, + target: 'node20', + }, }; function getOptions() { @@ -122,14 +124,18 @@ function getOptions() { return options; } +/** + * Nano build process. + * @param {import('esbuild').BuildOptions} options + */ async function nanoBuild(options) { const alsoCjs = options.format === 'esm' && options.cjs; delete options.cjs; - if (alsoCjs) { + if (options.format === 'esm' || options.format === 'cjs') { options.outExtension = { + '.js': options.format === 'esm' ? '.mjs' : '.cjs', ...options.outExtension, - '.js': '.mjs', }; }