Skip to content

[Feature]: Allow output.filename to be a function #2526

@dartess

Description

@dartess

What problem does this feature solve?

I want to have dynamic output path for different entry points.
In webpack I used it this way:

  output: {
    filename: ({ runtime }) => {
      switch (runtime) {
        case ENTRY_SW:
          return `${ENTRY_SW}.js`;
        case ENTRY_CHARTING_LIBRARY_CUSTOM_CSS:
          return `assets/lib/empty.js`;
        default:
          return `[name].[${hashType}].js`;
      }
    },
  },

I see that rspack can now accept a function for output: web-infra-dev/rspack#3483 .
If I understand correctly how does it work, it seems that now this can be implemented in rsbuild?

What does the proposed API look like?

type FilenameConfigValue = string | (pathData: JsPathData, assetInfo?: JsAssetInfo) => string;
type FilenameConfig = {
  js?: FilenameConfigValue;
  css?: FilenameConfigValue;
  svg?: FilenameConfigValue;
  font?: FilenameConfigValue;
  image?: FilenameConfigValue;
  media?: FilenameConfigValue;
};
  output: {
    filename: {
      js: ({ runtime }) => {
        switch (runtime) {
          case ENTRY_SW:
            return `${ENTRY_SW}.js`;
          case ENTRY_CHARTING_LIBRARY_CUSTOM_CSS:
            return `assets/lib/empty.js`;
          default:
            return `[name].[${hashType}].js`;
        }
      },
    },
  },

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions