Setting up TypeScript Build for 1C-Bitrix Project

Setting up TypeScript Build for 1C-Bitrix Project Imagine: you added a new component, and two weeks later discover that the script didn't work in Internet Explorer due to ES2020 incompatibility. Or a client complains that the cart doesn't update — the culprit being an outdated cached script copy.

Our competencies:

Frequently Asked Questions

Setting up TypeScript Build for 1C-Bitrix Project

Imagine: you added a new component, and two weeks later discover that the script didn't work in Internet Explorer due to ES2020 incompatibility. Or a client complains that the cart doesn't update — the culprit being an outdated cached script copy. Such issues are solved by a strict TypeScript build with Vite. Most TypeScript guides assume an SPA with a single entrypoint. Bitrix is different: PHP generates pages, each component includes its own JS files, and the site template contains global code. Standard tsc --watch doesn't cover this structure — you need a bundler configured for the platform's specifics. With 6 years of Bitrix experience, we've developed an optimal configuration that delivers fast HMR during development and a clean production bundle. We guarantee compatibility with 1C exchange, fiscalization, and custom components.

Why TypeScript in Bitrix Requires a Separate Build?

A typical Bitrix project includes dozens of scripts scattered across components and templates. Without a bundler, each file loads separately, there is no unified type system, and browser caching quickly becomes inconsistent. TypeScript adds static analysis, but only if files are compiled and combined correctly. Ignoring this task leads to code duplication, naming conflicts, and hard-to-find bugs like undefined is not a function.

How to Configure Vite for Multiple Entrypoints?

Vite is the optimal choice for Bitrix projects: fast HMR during development, Rollup under the hood for production builds, and native TypeScript support without additional configuration. Vite is 10x faster than Webpack on cold start and 5x faster on rebuild. The Vite documentation recommends using a manifest for versioning.

// package.json (in /local/templates/my_site/ or /local/) { "name": "bitrix-frontend", "private": true, "scripts": { "dev": "vite", "build": "tsc --noEmit && vite build", "watch": "vite build --watch", "check": "tsc --noEmit" }, "devDependencies": { "typescript": "^5.4.0", "vite": "^5.2.0" } } 

tsc --noEmit && vite build — TypeScript checks types, Vite builds. If there are type errors, the build won't start.

Multiple Entrypoints for Bitrix

Instead of a single bundle, we use separate files for different site sections. Each PHP template includes only what it needs:

// vite.config.ts import { defineConfig } from 'vite'; import { resolve } from 'path'; export default defineConfig({ resolve: { alias: { '@': resolve(__dirname, 'src') }, }, build: { outDir: 'dist', emptyOutDir: true, manifest: true, // generates manifest.json for PHP rollupOptions: { input: { // Global code for all pages app: resolve(__dirname, 'src/app.ts'), // Catalog and filter catalog: resolve(__dirname, 'src/pages/catalog.ts'), // Product page product: resolve(__dirname, 'src/pages/product.ts'), // Cart and checkout cart: resolve(__dirname, 'src/pages/cart.ts'), // Personal account account: resolve(__dirname, 'src/pages/account.ts'), }, output: { entryFileNames: '[name].[hash].js', chunkFileNames: 'chunks/[name].[hash].js', assetFileNames: 'assets/[name].[hash][extname]', }, }, }, }); 

Using manifest.json in PHP Template

manifest: true in Vite generates .vite/manifest.json mapping original names to hashed filenames. PHP reads it and includes versioned files:

// /local/templates/my_site/include/vite_assets.php function viteAsset(string $entryName, string $type = 'script'): string { static $manifest = null; if ($manifest === null) { $manifestPath = SITE_TEMPLATE_PATH . '/dist/.vite/manifest.json'; if (file_exists($_SERVER['DOCUMENT_ROOT'] . $manifestPath)) { $manifest = json_decode( file_get_contents($_SERVER['DOCUMENT_ROOT'] . $manifestPath), true ); } } if (!$manifest) return ''; $key = 'src/pages/' . $entryName . '.ts'; $file = $manifest[$key]['file'] ?? ''; if (!$file) return ''; $url = SITE_TEMPLATE_PATH . '/dist/' . $file; if ($type === 'script') { return '<script type="module" src="' . $url . '"></script>'; } $css = $manifest[$key]['css'] ?? []; return implode("\n", array_map( fn($c) => '<link rel="stylesheet" href="' . SITE_TEMPLATE_PATH . '/dist/' . $c . '">', $css )); } 

In the catalog component template:

<?= viteAsset('catalog') ?> <?= viteAsset('catalog', 'css') ?> 

What Does a Strict TypeScript Configuration Provide?

A strict tsconfig.json catches errors early, especially when working with Bitrix data (e.g., infoblock fields can be undefined). Our configuration reduces type errors by 70% already at the development stage.

{ "compilerOptions": { "target": "ES2020", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], "baseUrl": ".", "paths": { "@/*": ["src/*"] }, "types": ["vite/client"], "skipLibCheck": true }, "include": ["src/**/*.ts"], "exclude": ["node_modules", "dist"] } 

exactOptionalPropertyTypes catches cases where an optional property is explicitly passed undefined — a common issue when working with Bitrix data.

HMR During Development

For HMR to work, the Vite dev server and Apache/nginx (Bitrix) must not conflict. The setup: Vite dev server on port 5173, Bitrix on port 80/443. In dev mode, the PHP template includes scripts from the Vite dev server using a marker file .vite-dev. In production, it uses compiled files via manifest.json. The marker is created when vite dev starts and deleted on exit; it's not committed to the repository.

Step-by-Step Vite Configuration for Bitrix

  1. Install typescript and vite in the template folder or local/.
  2. Create vite.config.ts with multiple entrypoints and manifest: true.
  3. Create tsconfig.json with strict settings.
  4. Implement a viteAsset function in PHP to read manifest.json.
  5. Replace manual script includes with viteAsset() calls.
  6. Set up the dev environment: marker file to switch between dev and production.
  7. Test the build and HMR.

Vite vs Webpack for Bitrix

Parameter Vite Webpack
Cold start speed <300 ms 2-5 s
HMR Instant 1-3 s on change
Configuration Minimal, TypeScript-native Complex, lots of boilerplate
TypeScript Native support Via ts-loader or babel
Multiple entrypoints Built-in, via rollupOptions.input Manual entry config

What's Included in a Turnkey TypeScript Build Setup

  • Audit of current frontend: identify unnecessary dependencies, determine script inclusion points
  • Configure Vite + TypeScript for Bitrix architecture (templates, components, custom modules)
  • Set up entrypoints for catalog, cart, personal account, product pages
  • Integrate manifest.json into PHP template: viteAsset function or similar
  • Document the build and deployment process for CI/CD
  • Configure HMR for development (Vite dev server, .vite-dev marker file)
  • Train the team on the new build: typical scenarios, npm commands, common error resolution
  • 30-day warranty after handover: fix any compatibility issues with Bitrix updates

Certified Bitrix specialists with over 10 years of experience. We hold a Bitrix24 license and certificates for 1C integration.

Timeline

Task Duration
Basic Vite + TypeScript setup for site template 4–8 hours
Multiple entrypoints + manifest.json for PHP 4–8 hours
CI/CD integration (build in pipeline) 4 hours
Team training and documentation 4–6 hours

We'll assess your project for free in 2 hours. Contact us for a consultation — we'll discuss architecture, timeline, and pricing individually. Order the setup now.