Rspeedy logo
Rspeedy

Home > @lynx-js/rspeedy > Filename > bundle

Filename.bundle property

The name of the bundle files.

Signature:

bundle?: BundleFilename | undefined;

Default Value

'[name].[platform].bundle'

Remarks

The following placeholder is supported:

  • [name]: the name of the entry. - [contenthash]: the contenthash of the bundle. - [platform]: the environment name of the bundle.

Example 1

  • Using content hash in bundle filename:
import { defineConfig } from '@lynx-js/rspeedy'

export default defineConfig({
  output: {
    filename: {
      bundle: '[name].[contenthash].bundle',
    },
  },
})

Example 2

  • Using content hash with length in bundle filename:
import { defineConfig } from '@lynx-js/rspeedy'

export default defineConfig({
  output: {
    filename: {
      bundle: '[name].[contenthash:8].bundle',
    },
  },
})

Example 3

  • Using a function to control the main bundle and the lazy bundles separately (e.g. emit lazy bundles into another directory with a git commit hash appended):
import { execSync } from 'node:child_process'

import { defineConfig } from '@lynx-js/rspeedy'

const gitHash = execSync('git rev-parse --short HEAD').toString().trim()

export default defineConfig({
  output: {
    filename: {
      bundle: ({ lazyBundle, platform }) =>
        lazyBundle
          ? `my-lazy-bundles/[name].[fullhash]-${gitHash}.bundle`
          : `[name].${platform}.bundle`,
    },
  },
})
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.