Skip to content

feat: add inline sourcemap option to script and style compilers#112

Open
yusasa16 wants to merge 21 commits into
devfrom
feat/sourcemap-option
Open

feat: add inline sourcemap option to script and style compilers#112
yusasa16 wants to merge 21 commits into
devfrom
feat/sourcemap-option

Conversation

@yusasa16
Copy link
Copy Markdown
Collaborator

Summary

  • Add opt-in sourcemap?: boolean option to @kamado-io/script-compiler and @kamado-io/style-compiler. Default false; when true, emits an inline source map appended to the output.
  • script-compiler: passes sourcemap: 'inline' to esbuild — banner offsets are handled automatically by esbuild.
  • style-compiler: feeds the banner through PostCSS as a /*! important comment when sourcemap is enabled, so cssnano preserves it and the inline source map's line offsets stay correct.
  • Document the new option in each package README and in the kamado README (en/ja), including a Switching options per command example using process.argv.includes('server') to vary options between kamado server and kamado build.

Test plan

  • `yarn lint` — pass
  • `yarn build` — pass
  • `yarn test` — pass
  • Manually verify inline source maps appear in dev server output for both JS and CSS, and that they are absent in `yarn build` output when `sourcemap` is left unset

🤖 Generated with Claude Code

yusasa16 added 5 commits May 14, 2026 18:11
Add an opt-in `sourcemap?: boolean` option that emits an inline source map
(data URI appended as `//# sourceMappingURL=...`) when set to `true`
(default: `false`). esbuild adjusts mappings to account for the banner
automatically.
Add an opt-in `sourcemap?: boolean` option that emits an inline source map
appended to the output when set to `true` (default: `false`). When enabled,
feed the banner through PostCSS as a `/*!` important comment so cssnano
preserves it and the inline source map line offsets stay correct.
…ching

Add the new `sourcemap` option to the createStyleCompiler and createScriptCompiler
sections in both the English and Japanese READMEs, and add a "Switching options
per command" subsection showing how to branch on `process.argv` to vary compiler
options between `kamado server` and `kamado build`.
@yusasa16 yusasa16 requested a review from YusukeHirao as a code owner May 14, 2026 09:17
@yusasa16 yusasa16 self-assigned this May 15, 2026
yusasa16 added 16 commits May 15, 2026 18:10
Extend `sourcemap` from `boolean` to `boolean | 'onServer'`. When set to `'onServer'`,
the inline source map is emitted only while kamado runs in serve mode
(`context.mode === 'serve'`).
Extend `sourcemap` from `boolean` to `boolean | 'onServer'`. When set to `'onServer'`,
the inline source map is emitted only while kamado runs in serve mode
(`context.mode === 'serve'`).
…mmand example

Add the `'onServer'` value to the compiler sourcemap descriptions, and replace the
`process.argv`-based per-command switching example with a sourcemap-only example
that relies on the new built-in `'onServer'` value.
…ap flag

Previously the banner was prepended through PostCSS only when sourcemap was on,
and appended verbatim after processing when it was off — so cssnano touched the
banner in one path but not the other, producing slightly different output.

Always feed the banner into the PostCSS input via a new normalizeBanner() that
coerces it into a `/*! ... */` important comment, so cssnano preserves it in
both paths. The sourcemap option now only toggles `map: { inline: true }`.

Also notes that enableSourcemap is fixed for the lifetime of a command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants