Skip to content

bundle.config

Build configuration for an extension. Create bundle.config.ts in your extension directory:

ts
export default {
  input: './src/my.extension.ts',
  output: {
    js: './dist/my.extension.bundle.js',
    css: './dist/my.extension.bundle.css',
  },
  namespace: 'BX.MyExtension',
};

JavaScript configuration (bundle.config.js) is also supported.

Options

OptionTypeDescription
inputstringEntry point file
outputstring | {js, css}Output bundle path(s)
namespacestringGlobal namespace for exports
concat{js?: string[], css?: string[]}Concatenate files in specified order
targetsstring | string[]Browser targets for transpilation
sourceMapsbooleanGenerate source maps
minificationboolean | objectTerser minification options
treeshakebooleanRemove unused code (default: true)
pluginsPlugin[]Custom Rollup plugins
resolveNodeModulesbooleanResolve dependencies from node_modules
babelbooleanEnable/disable Babel transpilation (default: true)
standalonebooleanStandalone build with inlined dependencies
protectedbooleanProtect from rebuilding
rebuildstring[]Rebuild dependent extensions
transformClassesbooleanTranspile classes

Plugins

The plugins option accepts an array of Rollup-compatible plugins. Plugins are added at the end of the build chain, after Chef's built-in plugins.

Installation

Install the plugin in your extension directory:

bash
cd /path/to/my.extension
npm install @rollup/plugin-alias

Usage

ts
import alias from '@rollup/plugin-alias';
import { resolve } from 'node:path';

export default {
  input: './src/index.ts',
  output: './dist/my.bundle.js',
  namespace: 'BX.My',
  plugins: [
    alias({
      entries: [
        { find: '@utils', replacement: resolve(import.meta.dirname, 'src/utils') },
      ],
    }),
  ],
};

Multiple Plugins

ts
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';

export default {
  input: './src/index.ts',
  output: './dist/my.bundle.js',
  namespace: 'BX.My',
  plugins: [
    alias({
      entries: [
        { find: '@utils', replacement: './src/utils' },
      ],
    }),
    replace({
      __VERSION__: JSON.stringify('1.0.0'),
      preventAssignment: true,
    }),
  ],
};

Resolving node_modules

The resolveNodeModules option enables resolving dependencies from node_modules. By default, Chef treats all npm dependencies as external — they are not included in the bundle.

ts
export default {
  input: './src/index.ts',
  output: './dist/my.bundle.js',
  namespace: 'BX.My',
  resolveNodeModules: true,
};

When enabled:

  1. Install dependencies: npm install in the extension directory
  2. Dependencies from node_modules will be inlined into the bundle
  3. The bundle size will increase, but the extension becomes independent of npm

TIP

If you need full independence from Bitrix dependencies as well, use standalone mode.

Disabling Babel

The babel option allows disabling Babel transpilation. This is useful when the code is already pre-built and doesn't need Babel processing.

ts
export default {
  input: './src/index.ts',
  output: './dist/my.bundle.js',
  namespace: 'BX.My',
  babel: false,
};

WARNING

Without Babel, the code won't be transpiled for target browsers. Only use this option if you're sure the input code is already compatible with the required browsers.

Environment Variables

Chef automatically replaces environment variables during build, similar to Vite:

VariableProductionDevelopment
process.env.NODE_ENV"production""development"
import.meta.env.MODE"production""development"
import.meta.env.PRODtruefalse
import.meta.env.DEVfalsetrue

Replacement happens statically at build time. This enables tree-shaking to remove dev-only code from npm packages:

ts
if (process.env.NODE_ENV !== 'production') {
  console.warn('Debug info');
}

In chef build mode (no flags), variables are set to development. In chef build --production mode — to production.

Released under the MIT License.