Skip to content

Commit

Permalink
fix: refactor nano-build.cjs to include microservice preset and updat…
Browse files Browse the repository at this point in the history
…e all presets configs
  • Loading branch information
alimd committed Dec 23, 2023
1 parent 3b464d5 commit 3f662b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
12 changes: 7 additions & 5 deletions packages/nano-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,6 +54,7 @@ Add the following scripts to your `package.json`:
```js
{
...defaultPreset,
platform: 'node',
format: 'esm',
cjs: true,
mangleProps: '_$',
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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',
}
```

Expand Down
32 changes: 19 additions & 13 deletions packages/nano-build/nano-build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const defaultOptions = {
entryPoints: ['src/main.ts'],
outdir: 'dist',
logLevel: 'info',
platform: 'node',
target: 'es2020',
minify: true,
treeShaking: false,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -88,6 +81,15 @@ const presetRecord = {
'safari11',
],
},
microservice: {
platform: 'node',
format: 'esm',
treeShaking: true,
mangleProps: '_$',
sourcemap: false,
sourcesContent: false,
target: 'node20',
},
};

function getOptions() {
Expand Down Expand Up @@ -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',
};
}

Expand Down

0 comments on commit 3f662b8

Please sign in to comment.