Files
mokosh/vite.config.ts
Mark 49f087fe40 feat(01-10): wave-1 task-2 — welcome page bundle + Vite entries + web_accessible_resources
Plan 01-10 Wave 1: welcome page bundle staged with canonical Plan 01-12
tokens.css @import + chrome.i18n for D-08 tagline (Plan 01-12 path-B
contract).

Files created:
  - src/welcome/copy.ts (Russian non-tagline COPY map per D-03 Sober
    voice; WELCOME_HERO_RU_FALLBACK + WELCOME_HERO_EN_FALLBACK exported
    for the welcome.ts `|| <en-const>` fallback chain).
  - src/welcome/welcome.html (lang='ru'; data-mokosh-key + data-mokosh-
    i18n-key attribute conventions; SINGLE stylesheet link; D-02 Hero +
    body + footer structure; 10 keyed attrs total; <title> populated
    via populateCopy).
  - src/welcome/welcome.css (FIRST LINE `@import '../shared/tokens.css';`;
    ZERO hex literals in source; 65 var(--mks-*) refs; D-02 layout +
    --mks-welcome-max-w=720px; --mks-rec madder for recording-related
    accents per D-04 Loom palette).
  - src/welcome/welcome.ts (vanilla DOM; populateCopy + populateI18n
    filter-pipeline form per project rule "no `continue`"; no `as any`;
    Logger from src/shared; document.readyState guard; no event
    handlers per D-16-toolbar informational charter).

Files modified:
  - vite.config.ts: rollupOptions.input gains `welcome:
    'src/welcome/welcome.html'`; __VITE_DEV__ + __MOKOSH_UAT__ defines
    untouched (Plan 01-12 Wave 5 baseline preserved verbatim).
  - vite.test.config.ts: mirror entry in dist-test/; mergeConfig pattern
    untouched.
  - manifest.json: web_accessible_resources block added after
    host_permissions, before background; storage permission preserved
    in permissions array; default_locale='en' + __MSG_*__ placeholders
    from Plan 01-12 Wave 3 preserved verbatim.

NO src/welcome/welcome-tokens.css file is created — Plan 01-12 must_have
#9 path-B contract: Plan 01-12 landed FIRST (b909c37 → 865d394; SUMMARY
2026-05-20); canonical src/shared/tokens.css is import-ready
(Lora @font-face + IBM Plex Sans + D-04 Loom palette + --mks-rec=
var(--mks-madder-600) = #b2543d); welcome.css @imports it directly. No
placeholder transition needed.

Verify (all GREEN):
  - grep -F "@import '../shared/tokens.css'" src/welcome/welcome.css: exit 0
  - grep -E '#[0-9a-fA-F]{3,8}' src/welcome/welcome.css: exit 1 (zero hex)
  - grep -c 'var(--mks-' src/welcome/welcome.css: 65 (>= 5 required)
  - grep -oE 'data-mokosh-(i18n-)?key=' welcome.html | wc -l: 10 (>= 7)
  - npm run build: clean; dist/src/welcome/welcome.html present;
    dist/assets/welcome-D9oNz95l.css carries inlined tokens.css content
    (--mks-rec: var(--mks-madder-600); --mks-madder-600: #b2543d).
  - npm run build:test: clean; dist-test/src/welcome/welcome.html present;
    dist-test/assets/welcome-wB0e_R_n.js bundled.
  - npx tsc --noEmit: clean.
  - dist/manifest.json preserves "default_locale": "en" + __MSG_extName__
    + web_accessible_resources block present (Vite/crxjs propagated).
  - Vitest baseline preserved: Task 1's 3-test file unchanged
    (1 RED + 2 vacuous-GREEN; Task 3 flips Test A to GREEN).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 09:09:22 +02:00

75 lines
3.0 KiB
TypeScript

import { defineConfig } from 'vite';
import { crx } from '@crxjs/vite-plugin';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import manifest from './manifest.json';
export default defineConfig({
plugins: [
crx({
manifest,
contentScripts: {
injectCss: false,
},
}),
nodePolyfills({
include: ['buffer'],
globals: {
Buffer: true,
global: false,
process: false,
},
protocolImports: false,
}),
],
resolve: {
alias: {
ebml: 'ebml/lib/ebml.js',
},
},
// `define` text-replaces token symbols at bundle time. We declare
// __MOKOSH_UAT__ as `false` in the production config so the gated
// hook-import branches in src/background/index.ts + src/offscreen/
// recorder.ts are static dead branches that Rollup tree-shakes. The
// test-only build (vite.test.config.ts) overrides this to `true`. We
// chose a dedicated token rather than gating on import.meta.env.MODE
// because vitest also uses MODE='test' by default — gating on MODE
// would activate the hooks during unit tests and overwrite the
// vi.fn() chrome.* mocks the existing 83-test baseline relies on.
// Reference: https://vite.dev/config/shared-options.html#define
define: {
__MOKOSH_UAT__: 'false',
// Plan 01-12 Wave 5 (RESEARCH §12 + D-09 spirit-satisfaction):
// Defensive token reserved for any future inline smoke-mode check.
// Currently the smoke harness lives entirely in `smoke.sh` outside
// Vite's input set — verified by `grep -rn 'smoke\|SMOKE\|data:text/html' src/`
// returning empty. Activated by setting the env var `VITE_DEV=1`
// before invoking `vite` / `vite build`; defaults to `false` so the
// gated branch (if any future plan adds one) is statically tree-
// shaken out of production. See scripts/README.md for the wider
// dev-script isolation invariant.
__VITE_DEV__: JSON.stringify(process.env.VITE_DEV === '1'),
},
build: {
// Plan 01-11: bump from default ES2020 to ES2022 so gated top-level
// await (`if (__MOKOSH_UAT__) { await import(...); }` in
// src/background/index.ts + src/offscreen/recorder.ts) compiles.
// The extension targets MV3 (Chrome ≥88); top-level await landed in
// Chrome 89 / Edge 89 / Firefox 89 / Safari 15 per MDN — comfortably
// inside the MV3 compatibility envelope.
// Reference: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/await#browser_compatibility
// Reference: https://vite.dev/config/build-options.html#build-target
target: 'es2022',
rollupOptions: {
input: {
offscreen: 'src/offscreen/index.html',
// Plan 01-10 D-17-onboarding: welcome page bundled into both
// production and test builds. The page is reached via
// chrome.runtime.getURL('src/welcome/welcome.html') from the
// SW's openWelcomeIfFirstInstall helper; it requires the
// manifest's web_accessible_resources block to be navigable.
welcome: 'src/welcome/welcome.html',
},
},
},
});