Skip to content

"How to use Vite for the backend?" Could be added to the faq #11284

Closed

Description

@robkorv

What was unclear or otherwise insufficient?

Hello, yesterday I run into a build issue that the migration classes were getting mangled when creating a production build for a vue project with vite.

he: Gre migration name is wrong. Migration class name should have a JavaScript timestamp appended.
  at ? (/assets/index-CfBXyhU_.js:220:193588)
  at Array.map(app:///<anonymous>)
  at hg.getMigrations(/assets/index-CfBXyhU_.js:220:193494)
  at hg.executePendingMigrations(/assets/index-CfBXyhU_.js:220:188761)
  at async dZ.runMigrations(/assets/index-CfBXyhU_.js:220:610108)
  at async dZ.initialize(/assets/index-CfBXyhU_.js:220:608756)
  at async Xre(/assets/index-CfBXyhU_.js:240:28843)

I found the solution in the end and would like to add it to the documentation.

Recommended Fix

Are you interested in a pull request that adds this information to the documentation in a similar way as is done for webpack? https://typeorm.io/faq#how-to-use-webpack-for-the-backend

The solution is using terser as for the minify with a regex matching the migration class names in mangle.keep_classnames and compress.keep_classnames.

This is the "vite.config.ts" that fixed the issue:

import legacy from '@vitejs/plugin-legacy';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    sourcemap: true,
    minify: 'terser',
    terserOptions: {
      mangle: { keep_classnames: /^Migrations\d+$/ },
      compress: { keep_classnames: /^Migrations\d+$/ },
    },
  },
  plugins: [vue(), legacy()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
});

Let me know if you want a pull-request where this information is added to https://github.com/typeorm/typeorm/blob/master/docs/faq.md

Additional Context

No response

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Activity

  1. michaelbromley commented on Feb 12, 2025

    @michaelbromley
    Member

    Hi,

    Yes, a PR would be welcome on this, thanks!

  2. robkorv commented on Feb 18, 2025

    @robkorv
    ContributorAuthor

    Awesome. I will create a one soon! ™

  3. robkorv commented on Feb 25, 2025

    @robkorv
    ContributorAuthor

    I created one. LMK what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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