Skip to content

Built JS code not fully minified when dynamic import is used #15300

@mdickopp

Description

@mdickopp

Describe the bug

Generated JS files that use dynamic imports are not fully minified. For example, when building the reproduction repository, a file dist/assets/index-q-SMFOy6.js is generated that contains some minified code, followed by the following code that is not minified:

function __vite__mapDeps(indexes) {
  if (!__vite__mapDeps.viteFileDeps) {
    __vite__mapDeps.viteFileDeps = []
  }
  return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
}

I would have expected that everything in this file is minified, including the __vite__mapDeps function.

Reproduction

https://github.com/mdickopp/vite-minification-issue

Steps to reproduce

  1. Clone the reproduction repository
  2. Change into the cloned directory
  3. Run npm install
  4. Run npm run build

System Info

System:
    OS: Linux 6.5 Debian GNU/Linux trixie/sid
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 27.93 GB / 31.28 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 18.19.0 - /usr/bin/node
    npm: 10.2.5 - ~/.npm/bin/npm
  Browsers:
    Chromium: 120.0.6099.71
  npmPackages:
    vite: ^5.0.7 => 5.0.7

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions