Rocket Logo Rocket Guides Docs Blog

Configuration: Overview

The configuration file is rocket.config.js or rocket.config.mjs.

The config files consists of the following parts:

import { rocketLaunch } from '@d4kmor/launch';

export default {
  presets: [rocketLaunch()],
  build: {
    emptyOutputDir: true,
    pathPrefix: 'subfolder-only-for-build',
    serviceWorkerFileName: 'service-worker.js',
  },
};

Rocket is primarily build around plugins for each of it's systems.

New plugins can be added and all default plugins can be adjusted or even removed by using the following functions.

export default {
  setupUnifiedPlugins: [],
  setupDevAndBuildPlugins: [],
  setupDevPlugins: [],
  setupBuildPlugins: [],
  setupEleventyPlugins: [],
  setupCliPlugins: [],
};

Adding Rollup Plugins

For some projects you might want to enable non-standard behaviors like importing JSON files as JavaScript.

import data from './data.json';

You can accomplish this with rollup and dev server plugins. Make sure to add both the dev-server plugin as well as the rollup plugin, so that the behaviors is the same during development as it is in the production build.

For these cases you can use setupDevAndBuildPlugins, which will automatically add the plugin for you to both rollup and dev-server:

import json from '@rollup/plugin-json';
import { addPlugin } from 'plugins-manager';

/** @type {Partial<import("@d4kmor/cli").RocketCliOptions>} */
const config = {
  setupDevAndBuildPlugins: [
    addPlugin({ name: 'json', plugin: json, location: 'top', options: { my: 'settings' } }),
  ],
};

export default config;

This will add the rollup plugin json with the id json at the top of the plugin list of rollup and the dev server. It needs to be at the top so further plugins down the line can work with json imports. For the Dev Server the plugins are automatically wrapped by @web/dev-server-rollup. Note that not all rollup plugins will work with the dev-server.

Modifying Options of Plugins

All plugins which are either default or are added via a preset can still be adjusted by using adjustPluginOptions.

import { adjustPluginOptions } from 'plugins-manager';

/** @type {Partial<import("@d4kmor/cli").RocketCliOptions>} */
const config = {
  setupDevAndBuildPlugins: [adjustPluginOptions('json', { my: 'overwrite settings' })],
};

export default config;