farm-fe / farm

Extremely fast Vite-compatible web build tool written in Rust
https://farmfe.org
MIT License
4.83k stars 158 forks source link

[Feature Request]: `compilation.resolve.dedupe` config option #1719

Closed Rajaniraiyn closed 3 days ago

Rajaniraiyn commented 3 weeks ago

What problem does this feature solve?

In certain React projects, multiple React-specific packages may enforce different versions of React, leading to version mismatches and resulting in compilation errors. This problem often occurs when various packages reference different React versions, causing conflicts and inconsistent behavior during project compilation.

This feature aims to provide a solution by enforcing a unified version of React within the project, preventing version mismatch errors. This can be particularly beneficial in complex React projects where dependency management is crucial.

For reference, see Vite’s config options: Vite Config - Resolve Dedupe.

What does the proposed API look like?

this config option should be part of existing ResolveOptions as follows

interface ResolveOptions {
  extensions?: string[];
  alias?: Record<string, string>;
  mainFields?: string[];
  conditions?: string[];
  symlinks?: boolean;
  strictExports?: boolean;
  resolve?: string[];  // New API for enforcing a single version of a package during compilation
}
wre232114 commented 3 weeks ago

We'll support it later

gustawdaniel-statscore commented 3 weeks ago

I was trying to migrate all our projects from vite to farm today and seen that resolve-alias is unsupported.

https://vitejs.dev/config/shared-options.html#resolve-alias

there is my ferm.config

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import * as path from 'path';
import Components from 'unplugin-vue-components/vite';
import { BootstrapVueNextResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  base: process.env.E2E ? '/' : '/route/sms',
  plugins: [
    vue(),
    Components({
      resolvers: [BootstrapVueNextResolver()],
    }),
    // commonjs(),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  server: {
    port: 8889,
  },
  define: {
    // enable hydration mismatch details in production build
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true',
  },
  // @ts-expect-error defineConfig of vite not contain vitest type
  test: {
    setupFiles: ['vitest-localstorage-mock'],
    mockReset: false,
    include: ['src/**/*.spec.{ts,js}'],
  },
});

and error

[ Farm ] Error: Failed to load config file: Validation error: Unrecognized key(s) in object: 'base', 'resolve', 'define', 'test'. 
 Please check your configuration file or command line configuration. 

so there are other keys that are available in vite but not supported here.

Maybe it would be useful to write about partial compatibility and create detailed table with status of vite options support.

ErKeLost commented 3 weeks ago

@gustawdaniel-statscore

the first point

  1. The configuration in farm is wrapped in compilation except for server and plugin and some env configurations

  2. trans base to compilation: { output: { publicPath: "" } }

  3. define and resolve same like point 2, put their in compilation

  4. no test config

https://www.farmfe.org/docs/config/compilation-options

Rajaniraiyn commented 3 weeks ago

We'll be supporting this later.

@wre232114 Is there any roadmap or timeline for this feature?

wre232114 commented 2 weeks ago

it will be supported this week, you can use resolve.alias as work-around for now

Rajaniraiyn commented 2 weeks ago

Thank you so much

Rajaniraiyn commented 5 days ago

@wre232114 any updates on this?

ErKeLost commented 3 days ago

@Rajaniraiyn Sorry, due to some other work reasons, we will implement this feature this week