CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-webpack-bundle-analyzer

Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-4/

Bundle Report Configuration Utility

Create a utility that configures webpack-bundle-analyzer to generate customized bundle analysis reports for different deployment environments.

Requirements

Your task is to implement a configuration generator that creates webpack-bundle-analyzer plugin instances with customized report settings based on the deployment environment.

The utility should export a function createAnalyzerConfig(environment) that accepts an environment name and returns a configured BundleAnalyzerPlugin instance.

Environment-Specific Behavior

For "production" environment:

  • Generate a static HTML report
  • Report title should be: "Production Bundle Analysis - [current date and time]"
  • Report filename should be: "reports/production-bundle-report.html"

For "staging" environment:

  • Generate a static HTML report
  • Report title should be a function that dynamically generates the title (returns a string with "Staging Build" prefix and current timestamp)
  • Report filename should be: "reports/staging-bundle-report.html"

For "development" environment:

  • Start the analyzer server (default server mode)
  • Report title should be: "Dev Bundle Analysis"
  • Do not open the browser automatically

For any other environment:

  • Throw an error with message: "Unsupported environment: [environment name]"

Additional Requirements

  • All configurations should disable the default browser opening behavior except when explicitly needed
  • The function should return a properly instantiated BundleAnalyzerPlugin object, not just a configuration object

@generates

API

/**
 * Creates a configured webpack-bundle-analyzer plugin instance for the specified environment.
 *
 * @param {string} environment - The deployment environment ('production', 'staging', or 'development')
 * @returns {BundleAnalyzerPlugin} Configured plugin instance
 * @throws {Error} If environment is not supported
 */
function createAnalyzerConfig(environment) {
  // IMPLEMENTATION HERE
}

module.exports = { createAnalyzerConfig };

Test Cases

  • Given environment "production", returns plugin with static mode, title "Production Bundle Analysis - [date]", and filename "reports/production-bundle-report.html" @test
  • Given environment "staging", returns plugin with static mode, title function, and filename "reports/staging-bundle-report.html" @test
  • Given environment "development", returns plugin with server mode, title "Dev Bundle Analysis", and openAnalyzer set to false @test
  • Given unsupported environment "testing", throws error "Unsupported environment: testing" @test

Dependencies { .dependencies }

webpack-bundle-analyzer { .dependency }

Provides bundle analysis and visualization capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-webpack-bundle-analyzer

tile.json