diff --git a/src/commands/build.ts b/src/commands/build.ts index 1795caf..26b5c65 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -44,6 +44,11 @@ type BuildOptions = { * default to .env. */ env?: string; + /** + * flag: default false + */ + sourcemap?: boolean; + }; const CommandHandlerPlugin = (buildConfig: Partial, ambientFilePath: string, sernTsConfigPath: string) => { @@ -76,6 +81,7 @@ export async function build(options: Record) { if (!options.supressWarnings) { console.info(`${magentaBright('EXPERIMENTAL')}: This API has not been stabilized. add -W or --suppress-warnings flag to suppress`); } + console.log(options) const sernConfig = await getConfig(); let buildConfig: BuildOptions; const buildConfigPath = p.resolve(options.project ?? 'sern.build.js'); @@ -85,6 +91,7 @@ export async function build(options: Record) { format: options.format ?? 'esm', mode: options.mode ?? 'development', dropLabels: [], + sourcemap: options.sourceMaps, tsconfig: resolveBuildConfig(options.tsconfig, sernConfig.language), env: options.env ?? '.env', include: [] @@ -120,6 +127,7 @@ export async function build(options: Record) { console.log(' ', magentaBright('mode'), buildConfig.mode); console.log(' ', magentaBright('tsconfig'), buildConfig.tsconfig); console.log(' ', magentaBright('env'), buildConfig.env); + console.log(' ', magentaBright('sourceMaps'), buildConfig.sourcemap); const sernDir = p.resolve('.sern'), [ambientFilePath, sernTsConfigPath, genDir] = @@ -139,6 +147,7 @@ export async function build(options: Record) { const ctx = await esbuild.context({ entryPoints, plugins: [CommandHandlerPlugin(buildConfig, ambientFilePath, sernTsConfigPath)], + sourcemap: buildConfig.sourcemap, ...defaultEsbuild(buildConfig.format!, buildConfig.tsconfig), dropLabels: [buildConfig.mode === 'production' ? '__DEV__' : '__PROD__', ...buildConfig.dropLabels!], }); diff --git a/src/index.ts b/src/index.ts index bf69233..2ee63eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,6 +61,7 @@ program .option('-W --suppress-warnings', 'suppress experimental warning') .option('-p --project [filePath]', 'build with the provided sern.build file') .option('-e --env', 'path to .env file') + .option('--source-maps', 'Whether to add source-maps to configuration', false) .option('--tsconfig [filePath]', 'Use this tsconfig') .action(async (...args) => importDynamic('build.js').then((m) => m.build(...args)));