Skip to content

Commit

Permalink
feat: Update nano-build options and presets
Browse files Browse the repository at this point in the history
This commit updates the nano-build options and presets in the nano-build.cjs file. It introduces a new developmentOptions object for sourcemap and sourcesContent settings. The dropLabels option is used to remove the __dev_mode__ label. The getOptions function now checks for the preset name and merges the corresponding presetOptions. The options object is then updated based on the devMode value, using either the nano-build-development or nano-build-production settings. Finally, null fields are removed from the esbuildOptions.
  • Loading branch information
alimd committed Oct 10, 2024
1 parent 043cca0 commit 293598e
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions packages/nano-build/nano-build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ const defaultOptions = {
define: {
__package_name__: `'${packageJson.name}'`,
__package_version__: `'${packageJson.version}'`,
__dev_mode__: devMode.toString(),
},
};

/**
* @type {import('esbuild').BuildOptions}
*/
const developmentOptions = {
sourcemap: true,
sourcesContent: true,
dropLabels: ['__dev_mode__'],
}

/**
* @type {DictionaryOpt<import('esbuild').BuildOptions & {cjs?: true}>}
*/
const presetRecord = {
default: {},
module: {
Expand Down Expand Up @@ -95,19 +108,33 @@ const presetRecord = {
function getOptions() {
let presetName = process.argv.find((arg) => arg.startsWith('--preset='))?.split('=')[1] ?? 'default';
console.log('🔧 preset: %s', presetName);
const presetOptions = presetRecord[presetName];
if (!presetOptions) {
if (!Object.hasOwn(presetRecord, presetName)) {
console.error('❌ preset not found', {preset: presetName});
process.exit(1);
}

const options = {
const presetOptions = presetRecord[presetName];

let options = {
...defaultOptions,
...presetOptions,
...packageJson['nano-build'],
...packageJson['nano-build-' + (devMode ? 'development' : 'production')],

};

if (devMode) {
options = {
...options,
...developmentOptions,
...packageJson['nano-build-development'],
}
} else {
options = {
...options,
...packageJson['nano-build-production'],
}
}

// Remove null fields from esbuildOptions
Object.keys(options).forEach((key) => {
if (options[key] === null) {
Expand Down

0 comments on commit 293598e

Please sign in to comment.